In my sample application in need find the user inactivity, ie if the user won't do anything for 5 minutes i need show a Alert Dialog. For this, initially i wrote my code in onStart()
method in this method i include a thread with which is run 5 minutes delay but it doesn't meet the exact requirement, i searched in Google i got on predefined method onUserInteracation()
, unfortunately i can't understand why this method (this method called when i interact the screen). Is it possible to find out the user inactivity through code?
Asked
Active
Viewed 342 times
0

Animesh Sinha
- 1,045
- 9
- 16

Aerrow
- 12,086
- 10
- 56
- 90
1 Answers
1
onUserInteraction is the correct function to check for any type of user activity. You can either set a timer which resets anytime onUserInteraction is called OR you can run a background thread that checks various constraints. I would probably go for a static timer instance that rests itself on user interaction.
@Override
public void onUserInteraction(){
//your static timer
CustomTimer.getInstance().resetTimer();
}
Check out a lengthy discussion here: How to detect USER INACTIVITY in android.

Community
- 1
- 1

rdrobinson3
- 360
- 1
- 4