Remove All Ads from XDA

Service terminates when app terminates

689 posts
Thanks Meter: 780
By aeppacher, Senior Member on 8th March 2014, 10:59 PM
Post Reply Email Thread
I am currently trying to implement an app that has a service running until the user explicitly ends it via the app. I would like the service to remain on otherwise. My current problem is that whenever the app is removed from the recent apps, it terminates the service as well. I have tried using START_STICKY in my onStartCommand but it doesn't change anything.

public class TriggerService extends Service{

public int onStartCommand(Intent intent, int flags, int startId) {
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;

public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
and here is my code for when I call the service:

public void startServ(boolean state){
    editor = sp.edit();

    if (state == true) {
        startService(new Intent(currentActivity, TriggerService.class));
        editor.putBoolean("service_status", true);
        toast = Toast.makeText(currentActivity, "Service Running", Toast.LENGTH_SHORT);;
    } else {
        stopService(new Intent(currentActivity, TriggerService.class));
        editor.putBoolean("service_status", false);
        toast = Toast.makeText(currentActivity, "Service Not Running", Toast.LENGTH_SHORT);;

EDIT: I tried adding


to the manifest but it didn't help. I tried a few things that were recommended over here but so far no dice
9th March 2014, 01:41 AM |#2  
Junior Member
Thanks Meter: 20
Check this article, it also suggests a potential solution

And this open issue
The Following User Says Thank You to painlessDeath For This Useful Post: [ View ] Gift painlessDeath Ad-Free
9th March 2014, 03:19 AM |#3  
aeppacher's Avatar
OP Senior Member
Thanks Meter: 780
Originally Posted by painlessDeath

Check this article, it also suggests a potential solution

And this open issue

You are a god send. Tested the app on JB and the service stayed when I closed the app. Thank god.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes