I need to have ALWAYS a background service that will synchronize my Android application and a server. I know how to launch it through my application, but when the Android turns off, then the background service will die.
How can I do to keep the background service always running? (Even when the device turns off and then turns on…)
I need to add to the starts programs of Android my background service. Any hints?
use
<action android:name="android.intent.action.BOOT_COMPLETED" />for starting your service when the device turns on.In
AndroidManifest.xml:Add permission in your
AndroidManifest.xmlas:In code part
BootBroadcastReceiver:EDIT: if you are talking about device screen on/off then you need to register
<action android:name="android.intent.action.USER_PRESENT" />and<action android:name="android.intent.action.SCREEN_ON" />for starting your service when user is present or screen is on.