User Inactivity in android?

android

Solution

During my Serach I found a lot of answers but this is the best answer I got. But limitation of this code is that it works only for activity not for whole application. Take this as a reference.

myHandler = new Handler();
myRunnable = new Runnable() {
    @Override
    public void run() {
        //task to do if user is inactive

    }
};
@Override
public void onUserInteraction() {
    super.onUserInteraction();
    myHandler.removeCallbacks(myRunnable);
    myHandler.postDelayed(serviceRunnable, /*time in milliseconds for user inactivity*/);
}

for e.g you used 8000, the task will be done after 8 seconds of user inactivity.

Problem

I want to see for user inactivity in my android app.If user does not perform any activity say for 1 min then the app should go offscreen meaning it should display a dialogbox asking for the password(previously stored in sharedpreferences).If password matches the activity should start up again.Can some body please help me out in this I dont understand from were to start or what to search for.Or can some one provide me some links do achieve this?

Original source

Related problems