Я создал липкий сервис Foreground, который перезапускается каждый раз, когда его убивают, кажется, он работает нормально, но я заметил, что в некоторых случаях (когда ОС его убивает) он просто не перезапускается.Как я могу заставить его перезапустить КАЖДЫЙ раз, когда его убьют?Я хочу, чтобы эта служба работала всегда.
![I want it to run like those](https://i.stack.imgur.com/wBuQj.jpg)
Как и эти службы.
Это моя служба Foreground onStartCommand:
public int onStartCommand(Intent intent, int flags, int startId) {
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,
0, notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("InsiteMobile Service")
.setContentText("Run the app by clicking here")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pendingIntent)
.build();
Log.i("InsiteMobileLog", "Service Started");
startForeground(1, notification);
//do heavy work on a background thread
//stopSelf();
return START_STICKY;
}
Ивот как я вызываю службу в MainActivity onCreate ():
public void startService() {
Intent serviceIntent = new Intent(this, AppService.class);
serviceIntent.putExtra("inputExtra", "InsiteMobileService");
ContextCompat.startForegroundService(this, serviceIntent);
}