欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Android靜態(tài)注冊無(wú)法接受系統廣播問(wèn)題

概要

     工作中遇到一個(gè)問(wèn)題:監控應用的后臺Service需要一直運行不退出。為了選用合適的方法,搜索了網(wǎng)上常用保持進(jìn)程或者Service不被殺死的方法,監聽(tīng)開(kāi)機廣播、解鎖屏廣播等有規律廣播是很好的選擇。當應用運行在android2.x版本上時(shí)一切正常,但是在android4.x版本上發(fā)現應用被用戶(hù)在系統Settings中強制force stop后,無(wú)法監聽(tīng)到此類(lèi)廣播,導致監控應用不能正常運行。
     調查發(fā)現,這是android系統在3.1版本以后為了加強系統安全性和優(yōu)化性能對系統廣播進(jìn)行了限制。

Service運行不退出的常用方法

    總結常用保證進(jìn)程或者Service后臺運行不退出的方法如下:
     1. 應用監控開(kāi)機廣播boot_completed、解鎖屏廣播user_present、網(wǎng)絡(luò )連接狀態(tài)改變廣播CONNECTIVITY_CHANGE等有規律的系統廣播
         --android3.1以后,首次安裝未啟動(dòng)或者用戶(hù)強制force stop后,應用無(wú)法監聽(tīng)到
         --應用啟動(dòng)后,可以接收到上述廣播,但是會(huì )導致手機啟動(dòng)變慢,耗電明顯
     2. 放到系統應用system/app/或者system/priv-app/目錄下永遠可以監聽(tīng)1中的廣播
         --僅適用于預裝應用,或者手機已經(jīng)root可以操作系統目錄
     3. 設置應用的application屬性persistent為true,保證應用開(kāi)機后一直后臺運行
         --僅適用于系統應用,第三方應用無(wú)效果
     4. 開(kāi)啟兩個(gè)獨立應用進(jìn)程,相互監控,一方被kill,由對方立即啟動(dòng)
         --一個(gè)應用內開(kāi)啟兩個(gè)進(jìn)程,android3.1以后被用戶(hù)force stop后依然無(wú)法監聽(tīng)到1中的廣播
         --開(kāi)啟兩個(gè)獨立應用進(jìn)程,首次啟動(dòng)后可以實(shí)現相互監控。但是用戶(hù)體驗不好,需要安裝兩個(gè)apk。
     5. Service中調用AlarmManager的定時(shí)器功能,周期性檢查啟動(dòng)Service
         --由于pending Intent由系統AlarmManager發(fā)送,android3.1以后應用被force stop后無(wú)法收到
         --定期發(fā)送造成應用耗電明顯
     6. Service內部處理,保證不退出
         --在onStartCommand中設置start_sticky的返回值,可以保證Service因內存不足被kill、內存可用時(shí)被重啟
         --在onDestory時(shí)重啟該Service
         --提高Service優(yōu)先級:調用startForeground設置service為前臺
         --應用被force stop后這些方法無(wú)效
    不過(guò)在android3.1以后的版本上,對于第三方APK,上述幾種方法僅能盡量保證進(jìn)程或者service不退出,但不是100%保證。

Android對于系統廣播的控制

      從Android3.1開(kāi)始,android對于系統發(fā)送的廣播進(jìn)行了限制,原文如下:

Launch controls on stoppedapplicationsStarting from Android 3.1, the system's package manager keeps track ofapplications that are in a stopped state and provides a means of controllingtheir launch from background processes and other applications.Note that an application's stopped state is not the same as an Activity'sstopped state. The system manages those two stopped states separately.The platform defines two new intent flags that let a sender specifywhether the Intent should be allowed to activate components in stoppedapplication.FLAG_INCLUDE_STOPPED_PACKAGES —Include intent filters of stopped applications in the list of potential targetsto resolve against.FLAG_EXCLUDE_STOPPED_PACKAGES —Exclude intent filters of stopped applications from the list of potentialtargets.When neither or both of these flags is defined in an intent, the defaultbehavior is to include filters of stopped applications in the list ofpotential targets.Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGESto all broadcastintents. It does this to prevent broadcasts from backgroundservices frominadvertently or unnecessarily launching components of stoppped applications.A background service or application can override this behavior by adding theFLAG_INCLUDE_STOPPED_PACKAGES flag to broadcastintents that should be allowed to activate stopped applications.Applications are in a stopped state when they are first installed but are notyet launched and when they are manually stopped by the user (in ManageApplications).

Android官方API說(shuō)明:http://developer.android.com/about/versions/android-3.1.html#launchcontrols

      對于上述描述總結如下:
      1.在A(yíng)ndroid3.1以后版本添加了標志FLAG_INCLUDE_STOPPED_PACKAGES和FLAG_EXCLUDE_STOPPED_PACKAGES,用于區分發(fā)送廣播時(shí)是否啟動(dòng)激活那些未啟動(dòng)過(guò)或者被用戶(hù)force stop的應用組件。當兩個(gè)Flag都不設置或都設置的時(shí)候,默認操作是FLAG_INCLUDE_STOPPED_PACKAGES。
      2.系統向所有的Intent的廣播添加了FL??AG_EXCLUDE_STOPPED_PACKAGES標志。它這樣做是為了防止廣播無(wú)意中的或不必要地開(kāi)啟組件的stoppped應用程序的后臺服務(wù)。這樣可以?xún)?yōu)化系統性能,提高安全性,不過(guò)對于監控類(lèi)軟件是一個(gè)沉重的打擊。
      3.用戶(hù)給自定義的廣播Intent添加FLAG_INCLUDE_STOPPED_PACKAGES,用于啟動(dòng)stop狀態(tài)的應用組件。但是系統自帶的廣播intent,我們無(wú)能為力。
      綜上,在android3.1以后,系統加強了廣播的限制,對于進(jìn)程或者service長(cháng)時(shí)間運行不退出沒(méi)有有效的解決方案??傮w來(lái)看,啟動(dòng)兩個(gè)獨立應用進(jìn)程是一個(gè)不錯的選擇,一旦用戶(hù)啟動(dòng)應用后,即使點(diǎn)擊force stop,也可以由另一個(gè)應用啟動(dòng)。概要

     工作中遇到一個(gè)問(wèn)題:監控應用的后臺Service需要一直運行不退出。為了選用合適的方法,搜索了網(wǎng)上常用保持進(jìn)程或者Service不被殺死的方法,監聽(tīng)開(kāi)機廣播、解鎖屏廣播等有規律廣播是很好的選擇。當應用運行在android2.x版本上時(shí)一切正常,但是在android4.x版本上發(fā)現應用被用戶(hù)在系統Settings中強制force stop后,無(wú)法監聽(tīng)到此類(lèi)廣播,導致監控應用不能正常運行。
     調查發(fā)現,這是android系統在3.1版本以后為了加強系統安全性和優(yōu)化性能對系統廣播進(jìn)行了限制。

Service運行不退出的常用方法

    總結常用保證進(jìn)程或者Service后臺運行不退出的方法如下:
     1. 應用監控開(kāi)機廣播boot_completed、解鎖屏廣播user_present、網(wǎng)絡(luò )連接狀態(tài)改變廣播CONNECTIVITY_CHANGE等有規律的系統廣播
         --android3.1以后,首次安裝未啟動(dòng)或者用戶(hù)強制force stop后,應用無(wú)法監聽(tīng)到
         --應用啟動(dòng)后,可以接收到上述廣播,但是會(huì )導致手機啟動(dòng)變慢,耗電明顯
     2. 放到系統應用system/app/或者system/priv-app/目錄下永遠可以監聽(tīng)1中的廣播
         --僅適用于預裝應用,或者手機已經(jīng)root可以操作系統目錄
     3. 設置應用的application屬性persistent為true,保證應用開(kāi)機后一直后臺運行
         --僅適用于系統應用,第三方應用無(wú)效果
     4. 開(kāi)啟兩個(gè)獨立應用進(jìn)程,相互監控,一方被kill,由對方立即啟動(dòng)
         --一個(gè)應用內開(kāi)啟兩個(gè)進(jìn)程,android3.1以后被用戶(hù)force stop后依然無(wú)法監聽(tīng)到1中的廣播
         --開(kāi)啟兩個(gè)獨立應用進(jìn)程,首次啟動(dòng)后可以實(shí)現相互監控。但是用戶(hù)體驗不好,需要安裝兩個(gè)apk。
     5. Service中調用AlarmManager的定時(shí)器功能,周期性檢查啟動(dòng)Service
         --由于pending Intent由系統AlarmManager發(fā)送,android3.1以后應用被force stop后無(wú)法收到
         --定期發(fā)送造成應用耗電明顯
     6. Service內部處理,保證不退出
         --在onStartCommand中設置start_sticky的返回值,可以保證Service因內存不足被kill、內存可用時(shí)被重啟
         --在onDestory時(shí)重啟該Service
         --提高Service優(yōu)先級:調用startForeground設置service為前臺
         --應用被force stop后這些方法無(wú)效
    不過(guò)在android3.1以后的版本上,對于第三方APK,上述幾種方法僅能盡量保證進(jìn)程或者service不退出,但不是100%保證。

Android對于系統廣播的控制

      從Android3.1開(kāi)始,android對于系統發(fā)送的廣播進(jìn)行了限制,原文如下:

Launch controls on stoppedapplicationsStarting from Android 3.1, the system's package manager keeps track ofapplications that are in a stopped state and provides a means of controllingtheir launch from background processes and other applications.Note that an application's stopped state is not the same as an Activity'sstopped state. The system manages those two stopped states separately.The platform defines two new intent flags that let a sender specifywhether the Intent should be allowed to activate components in stoppedapplication.FLAG_INCLUDE_STOPPED_PACKAGES —Include intent filters of stopped applications in the list of potential targetsto resolve against.FLAG_EXCLUDE_STOPPED_PACKAGES —Exclude intent filters of stopped applications from the list of potentialtargets.When neither or both of these flags is defined in an intent, the defaultbehavior is to include filters of stopped applications in the list ofpotential targets.Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGESto all broadcastintents. It does this to prevent broadcasts from backgroundservices frominadvertently or unnecessarily launching components of stoppped applications.A background service or application can override this behavior by adding theFLAG_INCLUDE_STOPPED_PACKAGES flag to broadcastintents that should be allowed to activate stopped applications.Applications are in a stopped state when they are first installed but are notyet launched and when they are manually stopped by the user (in ManageApplications).

Android官方API說(shuō)明:http://developer.android.com/about/versions/android-3.1.html#launchcontrols

      對于上述描述總結如下:
      1.在A(yíng)ndroid3.1以后版本添加了標志FLAG_INCLUDE_STOPPED_PACKAGES和FLAG_EXCLUDE_STOPPED_PACKAGES,用于區分發(fā)送廣播時(shí)是否啟動(dòng)激活那些未啟動(dòng)過(guò)或者被用戶(hù)force stop的應用組件。當兩個(gè)Flag都不設置或都設置的時(shí)候,默認操作是FLAG_INCLUDE_STOPPED_PACKAGES。
      2.系統向所有的Intent的廣播添加了FL??AG_EXCLUDE_STOPPED_PACKAGES標志。它這樣做是為了防止廣播無(wú)意中的或不必要地開(kāi)啟組件的stoppped應用程序的后臺服務(wù)。這樣可以?xún)?yōu)化系統性能,提高安全性,不過(guò)對于監控類(lèi)軟件是一個(gè)沉重的打擊。
      3.用戶(hù)給自定義的廣播Intent添加FLAG_INCLUDE_STOPPED_PACKAGES,用于啟動(dòng)stop狀態(tài)的應用組件。但是系統自帶的廣播intent,我們無(wú)能為力。
      綜上,在android3.1以后,系統加強了廣播的限制,對于進(jìn)程或者service長(cháng)時(shí)間運行不退出沒(méi)有有效的解決方案??傮w來(lái)看,啟動(dòng)兩個(gè)獨立應用進(jìn)程是一個(gè)不錯的選擇,一旦用戶(hù)啟動(dòng)應用后,即使點(diǎn)擊force stop,也可以由另一個(gè)應用啟動(dòng)。

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
關(guān)于靜態(tài)注冊BroadcastReceiver接收不到廣播的問(wèn)題
android 開(kāi)機廣播接收不到的原因
Android 廣播的那些事兒
Android SERVICE后臺服務(wù)進(jìn)程的自啟動(dòng)和保持
Android面試題
小米手機部分廣播無(wú)法接收到的原因
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久