バックグラウンドで動作するサービスがあります。彼は START_STICKY を返します。これは、いくつかのイベントをリッスンするためです。このイベントは非常に高速に発生します (センサーからのデータ)。場合によっては、サービスが強制終了されます。null インテントがあり、ドキュメントによると、プロセスがなくなったためにサービスが強制終了されたときに発生する可能性があります。
回避方法が知りたいです。どんな助けでも大歓迎です。
アップデート
private void startForeground() {
String title = "Warning";//getString(R.string.note_title);
String text = "App still working";//getString(R.string.note_msg);
Intent intent = new Intent(this, DriverActivity.class);
PendingIntent pending = PendingIntent.getActivity(this, 0, intent, 0);
Bitmap bitmap = BitmapFactory.decodeResource(
getResources(),
R.drawable.ic_launcher);
Notification.Builder builder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(bitmap)
.setContentTitle(title)
.setContentText(text)
.setContentIntent(pending);
Notification notification = builder.getNotification();
notification.flags |= Notification.FLAG_NO_CLEAR;
startForeground(NOTIFICATION_ID, notification);
}