Here's how you can achieve this:
First, you need Runnable (), which will be launched when a timeout occurs (e.g. 10 seconds). The following is Runnable ():
private Runnable DoOnTimeOut = new Runnable() { public void run() {
Now in your activity you can call postDelayed for DoOnTimeOut:
Handler hl_timeout = new Handler(); @Override public void onCreate(Bundle b) { hl_timeout.postDelayed(DoOnTimeOut, 10000);
Now the most important part is that when you see the user interaction, you want to cancel the DoOnTimeOut call, and then set the call again for the next 10 seconds. The following is a method to override your activity for user interaction:
@Override public void onUserInteraction() { super.onUserInteraction();
I hope this will be helpful to you.
source share