Check app idle time

2

What is the most efficient way to check app idleness? I need to close the app if I do not interact with it for a certain amount of time. I have a functional solution, but perhaps there is something more appropriate that I have not found. Here's the 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 retrieving and saving the date of the last touch on the screen with% of%. I find it a bit costly, so ask the question.

    
asked by anonymous 01.09.2017 / 13:37

0 answers