Hai是否有可能检查广播接收器当前是否正在运行?如果可能,如何检查?
You can use dumpsys to help debug this for dynamically registered receivers:
adb shell dumpsys activity broadcasts
Use this in combination with grep and breakpoints in the debugger and you can find if your broadcast is registered at a certain time or not.
This is supposed to help with statically registered receivers, but I haven't used it myself:
adb shell dumpsys package
If you want to check it at runtime you can store a global boolean
variable and set it to false
and inside your onReceive()
set it to true
and before the onReceive()
exit set it back to false . any time you can check this global variable to tell if that broadcast receiver is running or not .
if you mean you want to know if its work or not make a message to the log cat example
onReceive(){
Log.d("my broadcast","works");
}
A BroadcastReceiver
is not intended to be running in the background. It'll be woken up and killed in limited scope.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.