Boot Reciever


A boot reciever is a listener that picks up an intent that is sent when the phone boot animation has stoped. the first thing that needs to be done with it is register it in the manifest

<uses-permission android:name=“android.permission.RECEIVE_BOOT_COMPLETED”/>

<receiver android:name=“com.lukemovement.example.BootResiever”>

<intent-filter>

<action android:name=“android.intent.action.BOOT_COMPLETED”/>

<action android:name=“android.intent.action.QUICKBOOT_POWERON”/>

</intent-filter>

</receiver>

the next bit is creating the activity that responds when the boot complete intent is recieved

package com.lukemovement.example;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.content.SharedPreferences;

public class BootResiever extends BroadcastReceiver

{

@Override

public void onReceive(Context context, Intent intent)

    {

if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {

//intent to start a new main activity

Intent i = new Intent(context, BootActivity.class);

i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

context.startActivity(i);

}

  }

}

and it is as simple as that