开发者

Idle time in android?

开发者 https://www.devze.com 2023-02-16 04:32 出处:网络
How can I dete开发者_JAVA百科rmine idle time in android? I wanted to show a popup if the application is idle for sometime,say some 60 secs.I don\'t think that the Android API provides anything that co

How can I dete开发者_JAVA百科rmine idle time in android? I wanted to show a popup if the application is idle for sometime,say some 60 secs.


I don't think that the Android API provides anything that could help you with this. Also have in mind that most devices will turn off the screen after one minute of inactivity. It will be better to leave the user/device to select when the screen needs to be turned off. You can capture the screen off and on events using Intent.ACTION_SCREEN_OFF and Intent.ACTION_SCREEN_ON. Instructions are provided here. You could show the dialog after the screen was turned off and on again.


capture a time stamp just before last activity performed and start a TimerTask for one time execution with the difference period of time stamp captured + 60 secs.


  1. Create a handler that checks a boolean. If true show a notification. If the boolean is false ( then send a delayed empty message to the handler after 60 secs. Reset the boolean to true)
  2. Send a delayed empty message to the handler after 60 secs
  3. In your activity, on every user interaction reset the boolean to false.
0

精彩评论

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

关注公众号