強制終了したサービスを再起動するようにしてください。
注:このサービスを他の場所からも停止している場合は、サービスを再開します。そのため、サービスを停止するか、強制的に停止したかをチェックする必要があります。 自分でサービスを停止する場合は、サービスの停止状態の種類[共有ではない]を[共有ではない]に保存し、その状態チェックを使用して再起動しないでください。
@Override
public void onTaskRemoved(Intent rootIntent){
Intent restartServiceIntent = new Intent(getApplicationContext(), this.getClass());
restartServiceIntent.setPackage(getPackageName());
PendingIntent restartServicePendingIntent = PendingIntent.getService(getApplicationContext(), 1, restartServiceIntent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
alarmService.set(
AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + 5000,
restartServicePendingIntent);
super.onTaskRemoved(rootIntent);
}
OSがサービスをシャットダウンすると再起動します。そうでない場合は、 – pskink
あなたはどのバージョンのAndroidを使用していますか? – JoxTraex
APIレベル24を使用しています – tarun