
很遇到过广播收不到的问题,比如Google Play推广安装广播没有收到等,诸如这些问题,又都是什么原因呢,这篇文章将进行回答。
从Android3.1(HoneyComb)也就是API12开始,Android引入了一套新的启动控制,这就是程序的停止状态。android框架揭秘那我么看一下Google对于程序的停止状态的描述。
什么是停止状态
Starting from Addroid3.1,the system's package manager keeps track of applications that are in a stopped state and provides a means of controllling their launch from background processes and other applications.
从Adroid3.1开始,系统的包管理器开始跟踪处理停止状态的程序。并且提供了方法来控制从后台进程或者其他程序对他们的启动。
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.
注意,程序的停止状态和Activity的停止状态不同,系统会单独处理这两种状态。
the platform defines two new intent flags that let a sender specify whether the Intent should be allowed to activate components in stopped application.
Android平台提供了两个Intent flags,用来让发送广播的一方决定广播是否需要同时发送给已经停止的程序。
Intent.FLAG_INCLUDE_STOPPED_PACKAGES —— Include intent filters of stopped applications in the list of potential targets to resolve against.
将已经支持的程序加入到能处理intent的目标处理者。
Intent.FLAG_EXCLUDE_STOPPED_PACKAGES —— Exclude intent filters of stopped application from the list of potential targets.
在能处理intent的目标处理者中不包含已经停止的程序。android框架揭秘
当如果intent中没有或者设置了上面两个flag,在目标处理者中是包含已经处理停止的程序。但是注意,系统会为所有的广播intent增加FLAG_EXCLUDE_STOPPED_PACKAGES这个flag.
为什么Android要引入这一状态
Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcast intents. It does this to prevent broadcasets from background services from inadvertently or unnecessarily launching components of stopped applications. A background service or application can override this behavior by adding the FLAG_INCLUDE_STOPPED_PACKAES flag to broadcast intents that should be allowed to activate stopped applications.
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-21669-1.html
加油↖
过的别太仔细了
还特么学法律的