title: How to make android Foreground Service Notification Sticky in Chinese ROMs?
body: <p>I tried everything to run service in background using foreground service and it works on all devices except chinese devices like vivo, oppo, oneplus. These devices kills the service as soon as the app is killed from recent list.</p>
  <p>Even the foreground notification is not sticky. It is swipeable. However, i want to show notification again as soon as it is cleared, Is there any way to do it?</p>
  <p>For example i have seen in app like IDM (Internet download manager) when downloading any file the notification remain visible. Even if it is cleared the notification pops again.</p>
  <p>How to get this type of functionality?</p>
  <p>My Code:</p>
  <p>MainActivity.java</p>
  <pre><code>
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
      public void startService(View v) {
          Intent serviceIntent = new Intent(this, ExampleService.class);
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {
              startForegroundService(serviceIntent);
          } else startService(serviceIntent);
      }
  
      public void stopService(View v) {
          Intent serviceIntent = new Intent(this, ExampleService.class);
          stopService(serviceIntent);
      }
  
  }
  </code></pre>
  <p>ExampleService.java</p>
  <pre><code>
      final Handler worker = new Handler();
  
      @Override
      public void onCreate() {
          super.onCreate();
          Log.d(&quot;Foreground Service&quot;, &quot;*********** Service Created ***********&quot;);
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
          worker.removeCallbacksAndMessages(null);
          Log.d(&quot;Foreground Service&quot;, &quot;*********** Service Destroyed ***********&quot;);
      }
  
      @Override
      public int onStartCommand(final Intent intent, int flags, int startId) {
          Intent notificationIntent = new Intent(this, MainActivity.class);
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  
          final NotificationCompat.Builder notification = new NotificationCompat.Builder(this, App.NOTIFICATION_CHANNEL_ID)
                  .setContentTitle(&quot;Example Service&quot;)
                  .setContentText(&quot;Working in background&quot;)
                  .setSmallIcon(android.R.drawable.sym_def_app_icon)
                  .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                  .setAutoCancel(false)
                  .setOngoing(true)
                  .setContentIntent(pendingIntent);
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) {
              notification.setCategory(Notification.CATEGORY_PROGRESS);
          }
          startForeground(1, notification.build());
  
          worker.post(new Runnable() {
              @Override
              public void run() {
                  Log.i(&quot;Info&quot;, Thread.currentThread().getName());
                  Toast toast = Toast.makeText(getApplicationContext(), &quot;Service Ping&quot;, Toast.LENGTH_SHORT);
                  toast.show();
                  Log.d(&quot;Foreground Service&quot;, &quot;*********** Service working ***********&quot;);
                  worker.postDelayed(this, 5000);
              }
          });
          return START_STICKY;
      }
  
      @Nullable
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  }
  </code></pre>