开发者

Detecting Android usage inactivity and setting a future alarm/intent to trigger

I have a repeating alarm setting, I have the activity being launched, the piece I'm missing is having this triggered after x minutes of inactivity.

开发者_JAVA技巧I'm considering keying off of SCREEN_OFF in a service and then setting an alarm and canceling it on SCREEN_ON, does anyone have an intent or other suggestion for this. I've considering polling for tasks, all kinds of pieces but I'm stuck.

Requirement: - App launches, alarm is set to relaunch app after 5 minutes, user exits/app exits after one minute - alarm triggers, detects phone is in use, resets alarm to trigger in fives minutes - if phone is idle relaunches app for one minute


Your question is ambiguous: "set to relaunch intent". Do you mean set to relaunch the activity with an intent or set to send an intent? What is the intent intended to accomplish?

If you wish to monitor screen on and off you simply need to register a broadcastreceiver in the manifest for the screen_off and screen_on intent, and run code depending on the intent that fired it: set a 5 minute delayed alarm on screen_off that is cancelled by the screen_on event.

Without knowing the purpose of the intent or why inactivity (assuming here you mean user inactivity as in screen_off/ cpu sleep) it's really hard to answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜