Force stop will make app's receiver not being

2019-06-25 06:06发布

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.

3条回答
疯言疯语
2楼-- · 2019-06-25 06:17

Try add FLAG_INCLUDE_STOPPED_PACKAGES

this FLAG in your Intent.

查看更多
手持菜刀,她持情操
3楼-- · 2019-06-25 06:23

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)

查看更多
霸刀☆藐视天下
4楼-- · 2019-06-25 06:32

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.

查看更多
登录 后发表回答