简体   繁体   English

Android应用程序刚启动后

[英]Android Application Just After Boot

I did a android application which launch just after boot finishes. 我做了一个Android应用程序,它在启动完成后启动。 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 ? 它适用于Android 2.3.3和Android 3.1,但当我强制关闭应用程序运行在Android 3.1和我再次重新启动应用程序不启动后?

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 对于测试,您可以在cmd中使用它

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

when i force closed application which runs in android 3.1 and i reboot again the application doesn't come after boot ? 当我强制关闭在Android 3.1中运行的应用程序并且我再次重新启动应用程序在启动后没有来?

Correct. 正确。 On Android 3.1+, the following types of applications will not run automatically: 在Android 3.1+上,以下类型的应用程序不会自动运行:

  • Applications that are newly installed 新安装的应用程序
  • Applications that the user has "force stopped" 用户已“强制停止”的应用程序

Those applications must first manually be started by the user (eg, launching one of your activities) before they will receive any broadcast Intents again. 这些应用程序必须首先由用户手动启动(例如,启动您的一项活动),然后才能再次收到任何广播Intents

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM