Situation
I want to implement a timeout in my app. If the user did not touch the screen within 2 minutes an inactivity fragment will be shown.
What i got so far
I am tracking the activity lifecycle using a custom Application
implementing Application.ActivityLifecycleCallbacks
. This way i know which Activity
is currently on top and can access its FragmentManager
to show my inactivity Fragment
on timeout. A background Thread
constantly checks if the last detected touch was longer ago than 2 minutes.
Problem
I dont know how to detect every touch that happens on the activity. I tried adding a OnTouchListener
to activity.getWindow().getDecorView().setOnTouchListener()
, but it is only called if the decorview is touched. If for instance a Button on top of it is touched my listener isn't notified. activity.getContentScene()' returns null for me, so i can't access the root
ViewGroup` like that either.
Question
How can i detect any touches that happen on a Activity or the whole Application?