How to detect user inactivity in Android

2019-01-01 08:04发布

User start my app and logs in.
Selects Session Timeout to be 5 mins.
Does some operations on the app. (all in foreground)
Now User bring Myapp to background and starts some other app.
----> Count down timer starts and logs out user after 5 mins
OR user turns the screen OFF.
----> Count down timer starts and logs out user after 5 mins

I want the same behavior even when the app is in the foreground but user doesn't interact with the app for a long-time say 6-7 mins. Assume the screen is ON all the time. I want to detect kind of user inactivity (No interaction with app even though the app is in the foreground) and kick start my count down timer.

13条回答
牵手、夕阳
2楼-- · 2019-01-01 09:05

There is no concept of "user inactivity" at the OS level, beyond the ACTION_SCREEN_OFF and ACTION_USER_PRESENT broadcasts. You will have to define "inactivity" somehow within your own application.

查看更多
登录 后发表回答