对于android开发人员来说,可能会发生这样的情况当你强行终止一个应用程序时,该应用程序不能接受到广播(该广播时在manifest文件中进行注册的),这是为什么呢?在我的第一印象中:只要时在manifest文件中注册的广播,只要运行过一次之后无论应用是处于什么状态都应该能接收到广播的,然而在anroid3.1中对于这个问题做了详细的说明。
下面是引自Android官方API说明,地址 http://developer.android.com/about/versions/android-3.1.html#launchcontrols
原文如下
Launch controls on stopped applications
Starting from Android 3.1, the system's package manager keeps track of applications that are in a stopped state and provides a means of controlling their launch from background processes and other applications.
Note that an application's stopped state is not the same as an Activity's stopped state. The system manages those two stopped states separately.
The platform defines two new intent flags that let a sender specify whether the Intent should be allowed to activate components in stopped application.
FLAG_INCLUDE_STOPPED_PACKAGES— Include intent filters of stopped applications in the list of potential targets to resolve against.FLAG_EXCLUDE_STOPPED_PACKAGES— Exclude intent filters of stopped applications from the list of potential targets.
When neither or both of these flags is defined in an intent, the default behavior is to include filters of stopped applications in the list of potential targets.
Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcast intents. It does this to prevent broadcasts from background services from inadvertently or unnecessarily launching components of stoppped applications. A background service or application can override this behavior by adding theFLAG_INCLUDE_STOPPED_PACKAGES flag to broadcast intents that should be allowed to activate stopped applications.
Applications are in a stopped state when they are first installed but are not yet launched and when they are manually stopped by the user (in Manage Applications).
在Android开发中,如果应用被强制停止,可能会导致无法接收预先在manifest中注册的广播。尽管通常认为manifest中注册的广播在应用运行后都能接收到,但自Android 3.1起,系统对此有了新的控制机制。官方API说明指出,从3.1版开始,系统会跟踪处于停止状态的应用,并提供了控制它们从后台进程和其他应用启动的方法。默认情况下,广播Intent不会激活已停止的应用组件,但可以通过设置特定标志来改变这一行为。

341

被折叠的 条评论
为什么被折叠?



