Skip to content Skip to sidebar Skip to footer

How To Keep Service Alive When Remove App From Stack

I want to show notification every minute using Alarm Manager, I have implemented below code, it's working fine but the problem is when I remove app from stack the service is not ru

Solution 1:

You need to start your service in foreground. You are missing something this in your service OnCreate() method.

startForeground(1337, notification);
return START_STICKY;

And don't stop your service in your activities or fragments onDestroy() methods.

Solution 2:

I tested this code on my phone with android 6.0 and on emulator with android 7.0 in both is working fine, even removing the application from the stack. The notification still working even removing the receiver code.

Solution 3:

You can try with receiver configuration process=":remote" to keep receiver alive. I faced with this problem and here is my solution.

Solution 4:

Did you try the code with any other output statements? Notifications are, off-late, not being fired for me either - I might blame Instant Run, nevertheless could you try replacing the notification-firing code snippet with maybe something like a Toast? Since Toasts don't work in services, maybe you could try creating a file in your external storage directory whenever the service starts to know that maybe it's up and running?

Post a Comment for "How To Keep Service Alive When Remove App From Stack"