繁体   English   中英

应用程序被杀死后取消注册后如何注册广播接收器

[英]How to register broadcast receiver once it is unregister after app is killed

嗨,我正在开发 android 应用程序,我希望在系统关闭所有服务后自动注册广播接收器,并在 Xiomi 中被杀死后取消注册广播接收器。

我想要类似的东西,一旦广播接收器被杀死,它就会自动注册,就像我们可以用start_sticky标志在服务中做的那样。

提前致谢。

不确定小米,但对于所有 Android 设备,这应该可以解决问题:- 导入:

import android.content.BroadcastReceiver;

此代码:

Intent intent = new Intent();
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
intent.setAction("com.example.Broadcast");
intent.putExtra("MyData", 1000);
sendBroadcast(intent);

请记住包括“intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);”

希望这可以帮助 ! :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM