Post Reply

Service terminates when app terminates

OP aeppacher

8th March 2014, 10:59 PM   |  #1  
aeppacher's Avatar
OP Senior Member
Thanks Meter: 725
 
622 posts
Join Date:Joined: Apr 2012
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.

Code:
public class TriggerService extends Service{

@Override
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;
}

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

Code:
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);
        toast.show();
    } else {
        stopService(new Intent(currentActivity, TriggerService.class));
        editor.putBoolean("service_status", false);
        toast = Toast.makeText(currentActivity, "Service Not Running", Toast.LENGTH_SHORT);
        toast.show();
    }

    editor.commit();
}
EDIT: I tried adding

Code:
android:isolatedProcess="true"

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: 2
 
13 posts
Join Date:Joined: Feb 2013
Check this article, it also suggests a potential solution
http://www.androidpolice.com/2014/03/07/bug-watch-stopping-apps-on-android-4-4-2-can-silently-kill-related-background-services-a-fix-is-on-the-way/


And this open issue
https://code.google.com/p/android/issues/detail?id=63793
The Following User Says Thank You to painlessDeath For This Useful Post: [ View ]
9th March 2014, 03:19 AM   |  #3  
aeppacher's Avatar
OP Senior Member
Thanks Meter: 725
 
622 posts
Join Date:Joined: Apr 2012
Quote:
Originally Posted by painlessDeath

Check this article, it also suggests a potential solution
http://www.androidpolice.com/2014/03...is-on-the-way/


And this open issue
https://code.google.com/p/android/is...etail?id=63793

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
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Java for Android App Development by ThreadRank