4

How can I make my application to get started while my phone boots up itself.

ankitjaininfo
  • 11,961
  • 7
  • 52
  • 75
Nandagopal T
  • 2,037
  • 9
  • 42
  • 54
  • 3
    Did you even try Google? http://www.androidsoftwaredeveloper.com/2009/03/20/how-to-start-on-boot/ – fredley Sep 01 '10 at 12:53
  • Duplicate of (amongst others): [How to Autostart an Android Application?](http://stackoverflow.com/questions/1056570/how-to-autostart-an-android-application) – Christopher Orr Sep 01 '10 at 15:21

1 Answers1

11

You need to use a BroadcastReceiver with android.intent.action.BOOT_COMPLETED intent.

Add following to your manifest file:

<receiver android:name="MyApp_Receiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</receiver>

MyApp_Receiver class implementing BoradcastReciever. Implement the onReceive() method and start your favorite activity from your app.

public void onReceive(Context context, Intent intent) {
    // make sure you receive "BOOT_COMPLETED"
    if ((intent.getAction() != null) && (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")))
    {
        // Start the service or activity 
    }
}
ankitjaininfo
  • 11,961
  • 7
  • 52
  • 75