Trying to start a service on boot on Android
Posted
by Alex
on Stack Overflow
See other posts from Stack Overflow
or by Alex
Published on 2010-05-06T20:56:39Z
Indexed on
2010/05/06
21:18 UTC
Read the original article
Hit count: 239
I've been trying to start a service when a device boots up on android, but I cannot get it to work.
I've looked a number of links online but none of the code is working. Am I forgetting something? This is my code.
Manifest
<receiver android:name=".StartServiceAtBootReceiver"
android:enabled="true"
android:exported="false"
android:label="StartServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action._BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<service android:enabled="true" android:name="com.test.RunService"/>
Receiver OnReceive
public void onReceive(Context context, Intent intent)
{
if("android.intent.action.BOOT_COMPLETED".equals(intent.getAction()))
{
Intent serviceLauncher = new Intent(context, RunService.class);
context.startService(serviceLauncher);
Log.v("TEST", "Service loaded at start");
}
}
Thanks,
© Stack Overflow or respective owner