简体   繁体   中英

Android: Not receiving TIME_TICK broadcast when application is not on top

I have a requirement to be able to monitor my application's state each minute even if the application is not on top.

SO I am using TIME_TICK broadcast for this. However, when the application is not on top, I am not receiving the broadcast. But, when my application is running on top I am getting it.

Any work around for this?

I assume you are registering the receiver at your manifest.xml file.

as the Android Documentation says:

Broadcast Action: The current time has changed. Sent every minute. You cannot receive this through components declared in manifests, only by explicitly registering for it with Context.registerReceiver().

I tried TIME_TICK in every way possible. The thing with TIME_TICK is that it is only active when the application concerned is up and running. Yes we do have to explicitly register for the broadcast from a Activity. But, even after that though I didn't unregister when exiting from the app, I was not getting the broadcast(Since Activity was dead so mostly the Broadcast registration was gone).

The solution which worked for me in this case is using AlarmManager, by setting a setRepeat alarm for each minute.

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.

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