How to start a service on phone BOOT
Views: 4304 | Date: 2013-08-16 22:21:33
I want to start a service when each time phone will restart.
Create a Broadcast receiver that should receive "BOOT_COMPLETED" broadcast. We must know that when a device finishes booting Android System sends "BOOT_COMPLTED" broadcast and inside that broadcast start service.
Registering the BootReciever in android manifest file :
Add the following permission in manifest :
Create Broadcast Receiver :
public class BootReceiver extends BroadcastReceiver
public void onReceive(Context context, Intent intent)
// Your code to execute when Boot Completd
Toast.makeText(context, "Booting Completed", Toast.LENGTH_LONG).show();
The onRecieve() method of BootReceiver will execute when boot completes, so we need to write the start service code inside onReceive() method.