Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android 4.0 無法接收開機廣播的問題

Android 4.0 無法接收開機廣播的問題

編輯:關於Android編程

前面的文章 Android 開機廣播的使用 中已經提到Android的開機啟動,但是在Android 4.0 有時可以接收到開機啟動廣播,有時卻不可以。經過分析發現,如果應用程序安裝上始終沒有被打開過,那麼在Android啟動時,該應用無法接收到開機啟動廣播android.permission.RECEIVE_BOOT_COMPLETED。

原來在Android 3.1的更新文檔中已經做了說明。

 

原文如下

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 3.1開始,系統的軟件包管理器跟蹤處於停止狀態(stopped state)的應用程序,提供了一種控制其啟動後台進程和其他應用程序方式。

需要注意的是應用程序的停止狀態(stopped state)和Activity的停止狀態是不一樣的。該系統可以分別管理這兩種停止狀態。

該平台定義了兩個新的Intent的Flag,讓發送者指定的意圖是否應該被允許激活停止的應用程序的組件。

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.排除停止的應用程序列表中的。

當兩個Flag都不設置或都設置的時候,默認操作是FLAG_INCLUDE_STOPPED_PACKAGES。

請注意,系統向所有的Intent的廣播添加了FL​​AG_EXCLUDE_STOPPED_PACKAGES標志。它這樣做是為了防止廣播無意中的或不必要地開啟組件的stoppped應用程序的後台服務。後台服務或應用程序可以通過向廣播Intent添加FLAG_INCLUDE_STOPPED_PACKAGES標志來喚醒處於停止狀態(stopped state)的應用程序。


應用程序處於停止狀態情況有兩種,一種是他們是第一次安裝,但尚未啟動,另一種是在管理應用程序中由用戶手動停止。

 

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved