Force stop will make app's receiver not being called?

丶灬走出姿态 提交于 2020-01-14 12:19:48

问题


I have a service declared in XML that responds to PACKAGE_ADDED broadcast intent. It works fine, but I just found out that if I force stop the app, the receiver won't receive anything anymore. It's not being called.

Is this normal? What can I do?

I need to make sure it always responds.


回答1:


Since version 3.1 of Android an application cant receive broadcast intents until its stared once manually. Before the first start, the application is considered as "Stopped" by the launcher. (http://developer.android.com/about/versions/android-3.1.html under "Launch controls on stopped applications").

If you manually force stop the application, this flag will be set again and you need to relaunch it manually to allow it to receive the events again.




回答2:


Try add FLAG_INCLUDE_STOPPED_PACKAGES

this FLAG in your Intent.




回答3:


If your receiver is registered dynamically by your service, when he is killed the receiver is also. But if you declare your receiver in XML this should work. (As usual boot receiver)



来源:https://stackoverflow.com/questions/17250706/force-stop-will-make-apps-receiver-not-being-called

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