Broadcast receiver not receiving intent

女生的网名这么多〃 提交于 2019-12-02 18:17:23

If your application only has a service and receivers then this won't work in Android 3.1 and later. The reason is that the system will not send broadcast Intents to application that are in the STOPPED STATE. An application is in the STOPPED STATE when it is first installed. It is removed from the STOPPED STATE when the user manually starts the application for the first time. It is returned to the STOPPED STATE if the user forces the application to stop using the application manager tool.

Since your application has no Activities, there is no way for the user to "start" it. Therefore it will never come out of the stopped state.

See http://developer.android.com/about/versions/android-3.1.html#launchcontrols

As Android Addict says in his comment to David Wasser's answer ... there is a way around this behaviour.

Just add the following flag to the calling Intent. This will ensure that you also reach broadcast receivers from "stopped" applications.

http://developer.android.com/reference/android/content/Intent.html#FLAG_INCLUDE_STOPPED_PACKAGES

You can read more about this Android 3.1 change here

http://developer.android.com/about/versions/android-3.1.html#launchcontrols

and here

http://code.google.com/p/android/issues/detail?id=18225

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!