I have an IntentService
.
In its OnCreate
I call startForeground(1, buildUpdatingAssignmentsNotification());
@NonNull
private Notification buildUpdatingAssignmentsNotification() {
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
Bitmap icon = BitmapFactory.decodeResource(this.getResources(), R.drawable.app_icon);
notificationBuilder.setSound(Uri.EMPTY)
.setVibrate(new long[]{0})
.setSmallIcon(R.drawable.app_icon)
.setLargeIcon(icon)
.setContentTitle(ASSIGNMENTS_GETTER_STARTED_MESSAGE)
.setAutoCancel(true)
.setProgress(0, 0, true);
return notificationBuilder.build();
}
In the end of OnHandleIntent
I call stopForeground(true);
(It is being called since I see the notification disappear) but the OnDestroy
method is not being called.
It works properly if I dont use the foreground thing and also this problem only happens when I start the IntentService
from an activity and close the app before the IntentService
finishes (it finishes the OnHandleIntent
anyway but doesnt call the OnDestroy
.
Any ideas how to fix this?