6

I did a android application which launch just after boot finishes. It works in android 2.3.3 and Android 3.1 but when i force closed application which runs in android 3.1 and i reboot again the application doesn't come after boot ?

Sarith Vasu
  • 81
  • 1
  • 5
  • Yeah it won't work in 3.1 [check this Thread](http://stackoverflow.com/questions/8531926/how-to-start-a-service-when-apk-is-installed-for-the-first-time) – Lalit Poptani Apr 17 '12 at 11:17

2 Answers2

2

i do it with this code and it works for me:

public class AutoStarter extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent)
    {
      if("android.intent.action.BOOT_COMPLETED".equals(intent.getAction()))
      {
         Intent serviceLauncher = new Intent(context, your.class);
         context.startService(serviceLauncher);
      }
    }
}

for testing you can use this in your cmd

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED

Boe-Dev
  • 1,585
  • 2
  • 14
  • 26
2

when i force closed application which runs in android 3.1 and i reboot again the application doesn't come after boot ?

Correct. On Android 3.1+, the following types of applications will not run automatically:

  • Applications that are newly installed
  • Applications that the user has "force stopped"

Those applications must first manually be started by the user (e.g., launching one of your activities) before they will receive any broadcast Intents again.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491