Skip to content Skip to sidebar Skip to footer

Run My Application In Background When I Start Device Power On In Android

Possible Duplicates: how to create startup application in android? How to Autostart an Android Application? Hi, I am trying in one of my application when i am going to start i m

Solution 1:

Here's a basic example of what I think you're trying to do. You'll need to do a few things. First, grant your application permission to listen for a "Boot completed" signal. In your AndroidManifest.xml, add this line in the manifest section:

<uses-permissionandroid:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Under your application section, add and specify a broadcast receiver for this intent:

<receiverandroid:name=".MyBroadcastReceiver"><intent-filter><actionandroid:name="android.intent.action.BOOT_COMPLETED" /></intent-filter></receiver>

You also need a broadcast receiver which will respond to this intent and start your service at boot. Create MyBroadcastReceiver.java in your project:

package com.mypackage.myapp;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

publicclassMyBroadcastReceiverextendsBroadcastReceiver {

    @OverridepublicvoidonReceive(Context aContext, Intent aIntent) {

        // This is where you start your service
        aContext.startService(newIntent(aContext, MyService.class));
    }
}

Post a Comment for "Run My Application In Background When I Start Device Power On In Android"