Keep Service running

You should create a sticky service. Read more about it here.

You can do this by returning START_STICKY in onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i("LocalService", "Received start id " + startId + ": " + intent);
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;
}

Read also about application:persistent which is “Whether or not the application should remain running at all times”. This is more troublesome – System will try not to kill your app which will effect others in the system, you should be careful using it.

Leave a Comment