Skip to content
This repository has been archived by the owner on Aug 19, 2021. It is now read-only.

Is there a better way to break user idle? #8

Open
paulshapiro opened this issue Jun 15, 2018 · 6 comments
Open

Is there a better way to break user idle? #8

paulshapiro opened this issue Jun 15, 2018 · 6 comments

Comments

@paulshapiro
Copy link
Contributor

Is there a more global way of detecting all screen input to break user idle than each activity intercepting touches via dispatchTouchEvent?

@KillerInk
Copy link

hi, i think you are looking for this:

Called whenever a key, touch, or trackball event is dispatched to the activity. Implement this method if you wish to know that the user has interacted with the device in some way while your activity is running.

https://developer.android.com/reference/android/app/Activity.html#onUserInteraction()

@paulshapiro
Copy link
Contributor Author

Yesss 🌠

@paulshapiro
Copy link
Contributor Author

Actually.. that's still per-activity right?

@KillerInk
Copy link

yes, its still per activity. you have to forward it to the class it need.

@KillerInk
Copy link

simple java sample how it could work

private Handler userIdleHandler =new Handler();

    Runnable userIdleExecuter =new Runnable() {
        @Override
        public void run() {
            setUserIsIdle();
        }
    };

    @Override
    public void onUserInteraction() {
        super.onUserInteraction();
        //remove old executer
        userIdleHandler.removeCallbacks(userIdleExecuter);
        //log user out after 10sec
        userIdleHandler.postDelayed(userIdleExecuter,10*1000);
    }

@KillerInk
Copy link

There is no global way to get the userinput.
You should see the Activity as the main entry.
You will face simliar problems when you need the ActivityContext.
If you need different Uis, its better to use Fragments and load it to the activity,instead of using different activitys.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants