user inactivity on a screen
I have a requirement where if the user does not respond in two minutes I have to record as missing interaction.
Usecase : pop up survey. If user doesn't respond(inactivity开发者_运维知识库) then I have to end the activity and record as missing data. How can I handle this usecase.
Android provides the CountDownTimer class. You could just start this timer when the activity loads and then if the user touches the screen cancel the timer, otherwise in the onFinish() of the CountDownTimer you would close the activity.
What I would do (certainly not the best solution), but I hope that can help you a little bit..
You can use the onUserInteraction to reset a timer.: http://developer.android.com/reference/android/app/Activity.html#onUserInteraction()
@Override
public void onUserInteraction(){
MyTimerClass.getInstance().resetTimer();
}
EDIT:
Something I found and may help: How to detect USER INACTIVITY in android
精彩评论