Search code examples
androidservice

How to create Android service running in background


How can I create a Service which keeps running when I end the app?

I searched really long on http://developer.android.com/ and Stack Overflow but I didn't found a solution. The Background Service needs something like doInBackground() from AsyncTask because I want to update my Data via HTTPUrlRequest with it.

UPDATE

I found a solution, I am using a Huawei P8 for developing which is running Android 5.0 with GUI EMUI 2.0, EMUI has a function which automatically disables background services (to save power) when not explicit defined in the "Secured Apps Menu", if you just run a Service it will kill this Service after 4 minutes (to save power), you have to run a new Thread in this Service to get a Service that keeps running as long as you want.

So for all EMUI users, please check this before you lose your hope like I did.


Solution

  • You need to use the intent service, it is used to handle your background service request and to control your app's background service actions

    here are few links to get you started on the topic:

    http://developer.android.com/training/run-background-service/index.html

    http://javatechig.com/android/creating-a-background-service-in-android