Reputation: 83
I am using SignalR to send notifications to my android client. For this, I am using Intent Service. The problem is that when I swipe out the app from recent apps, the service gets stopped. It is happening because IntentService is not running all the time but it works on Intent base.
Basically, I want to know whether I should use a Regular Service to receive notification constantly or is there any other way to keep intent service alive to do this.
Thanks in advance!
Upvotes: 2
Views: 563
Reputation: 211
IntentService is designed to do a piece of work then shut down, so can not use intent service for that.
For your task, you need to make service sticky return START_STICKY onStartCommand of the service. and in the doc, it's mentioned if the process is killed system will recreate again
if this service's process is killed while it is started (after returning from onStartCommand(Intent, int, int)), then leave it in the started state but don't retain this delivered intent. Later the system will try to re-create the service. Because it is in the started state, it will guarantee to call onStartCommand(Intent, int, int) after creating the new service instance; if there are not any pending start commands to be delivered to the service, it will be called with a null the intent object, so you must take care to check for this.
Upvotes: 1