简体   繁体   中英

Android: During alarm - if user locks screen or goes to home screen - how to bring it back again?

so I am facing small bit of so to call - exploit/bug. I have an app which triggers activity and wakes up phone from lockscreen and shows alarm, all works fine sound works but there are few scenarios in which I have problem: If user clicks home button it just minimizes app and thats it, it remains running in background. If user locks screen, the alarm is silenced - if unlocked within 10 seconds it continues, if unlocked after 10 seconds it's minimized and runs in background.

How would I go about fixing these? what approach would you suggest? I assume alarm activity goes into onPause? if so I was thinking of making new Handler and wake up phone in 10 seconds in onPause method but wondering if there is any better approach?

I dont think post a Handler is a good idea, there is no grantee that your Activity dos not get destroyed by Android system, and then you Handler will not work.

I suggest to set a new Alarm (after 10 seconds) that run a Service/Broadcast in onPause() , you can send the time of setting the Alarm in the PindingIntent . get that time check it or cancel the Alarm .

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