I wish to do something(call a function), if for a particular time interval the screen wasn’t touched or was remained inactive.
How can I achieve this in Android?
Any suggestions.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can send a delayed message to the handler of UI thread in
onResume()method:Then, in onTouchEvent remove the message and insert it again:
In your handler, override
handleMessage()method, to handle the message:Also, remove the message from the handler in
onPause().This assumes that your activity is active for the whole time (not paused etc.). Handling screen inactivity outside of your app seems impossible.