I have a service that works in background. He returns START_STICKY because it listens to some events, this events occurs very fast (data from sensors). I some cases my service is killed: I have got a null intent and according to documentation it can happens when my service has killed because his process go away.
http://developer.android.com/reference/android/app/Service.html#onStart%28android.content.Intent,%20int%29
I want to know how avoid it. Any help will be appreciated.
Update
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);
}