1

My app is running an IntentService to download data in the background. While doing so, it sends Notifications to update the user about the progress. The problem is, if the BatterySafe mode gets started, the IntentService gets killed, the Notifications stay there though (for example saying 30%).
Is there a way, to couple the lifecycle of the notification to the lifecycle of the service?

A second problem is, that I only want one instance of the IntentService. Is it possible, to achieve this?

In some Apps, for example the Avast AntiVirus, the background task seems connected to the notification, indicating that this background task is running. If this is a standard solution, it seems to solve my problem, so it would be great, if you could tell me the name.

zimmerrol
  • 4,872
  • 3
  • 22
  • 41
Luca Thiede
  • 3,229
  • 4
  • 21
  • 32
  • did you try `@Override public void onDestroy() { super.onDestroy(); // remove notificaiton here }` ? – Budius Nov 25 '16 at 20:31
  • That could solve the one problem, but it doesnt solve the problem, that I just want one instance of the intent service. Thats why I hoped there is a already built in solution (especially since other apps seem to use something like this) – Luca Thiede Nov 26 '16 at 10:48
  • Services (unless you're doing some multi process stuff) are always just one instance. – Budius Nov 26 '16 at 10:54
  • I know that for normals services, but also IntentServices? It seems, like there can be more instances.. – Luca Thiede Nov 26 '16 at 11:09
  • No. IntentServices extends from service, receive each 'onStartCommand' one at a time and queue them to be passed to 'onHandleIntent'. After no more commands are left, it stops. It's a pretty simple code that you can check easily with Android Studio decompiler. – Budius Nov 26 '16 at 11:54

0 Answers0