Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keeping background service alive after user exit app [duplicate]

I'm trying to create a service that will do background jobs for me even after the user closes the app from the running processes menu(by shifting process out of the screen).

What I tried to do is create service in a different process by declaring it like this:

  <service
        android:name=".service.Service"
        android:enabled="true"
        android:icon="@drawable/ic_launcher"
        android:process=":my_process" >
  </service>

and the onStartCommand() is:

    @Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return START_STICKY;
}
like image 655
Nativ Avatar asked Jul 20 '13 23:07

Nativ


People also ask

What does keep service alive in background mean?

A Background Service is a service that runs only when the app is running so it'll get terminated when the app is terminated. A Foreground Service is a service that stays alive even when the app is terminated.


1 Answers

According to the Android documentation you can achieve this behavior by using the attribute:

 android:isolatedProcess="true"

By the way, I know that it's not answering the question but it might help some people as well - lately, I found out about a great third-party lib that Evernote developers have created. Its name is Android-Job and its aim is to create jobs that run on different processes and can become active again even after a device reboot, it's amazing.

like image 140
Nativ Avatar answered Oct 05 '22 17:10

Nativ