Check app idle time

Asked

Viewed 65 times

2

What is the most efficient way to check for app idleness? I need to close the app if I haven’t interacted with it in a while. I have a working solution, but maybe there’s something more appropriate I couldn’t find. Follows current solution:

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    // compara data (Date) do útimo toque da tela com a data atual
    if(SavedUtil.isIdleExceeded(this)) {
        // Vai para tela de login
        handleLogout(null);
    }

    // salva data do último toque na tela
    SavedUtil.setLastAppTouch(this);

    return super.dispatchTouchEvent(ev);
}

I’m recovering and saving in SharedPreferences the date of the last touch on the screen. I find it a little costly, so the question.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.