To Start your application on startup of device.
First we have to create a BroadcastReceiver which will be started when boot completes as
onRecieve will be first called when the BroadcastReceiver MyService starts.
Next make an entry of this receiver in AndroidManifest.xml
First we have to create a BroadcastReceiver which will be started when boot completes as
public class MyService extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equalsIgnoreCase("android.intent.action.BOOT_COMPLETED"))
{
Intent myIntent=new Intent(context,package.YourActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
}
}
onRecieve will be first called when the BroadcastReceiver MyService starts.
Next make an entry of this receiver in AndroidManifest.xml
<receiver android:name=".MyService"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Here in intent filter we have declared the action as android.intent.action.BOOT_COMPLETED ,
so that this receiver and intent with action android.intent.action.BOOT_COMPLETED
so that this receiver and intent with action android.intent.action.BOOT_COMPLETED
Now this receiver will be intimated when boot completes
No comments:
Post a Comment