- Why is that?
I'm not 100% sure, but the documentation for this method gives a potential answer:
This callback and onUserLeaveHint()
are intended to help activities manage status bar notifications intelligently; specifically, for helping activities determine the proper time to cancel a notification.
Through this lens, it makes sense that you would get this callback when switching activities, regardless of whether a human interaction caused the switch.
- What are other alternatives for getting screen touches?
You could override dispatchTouchEvent(MotionEvent)
in a "base" Activity
class to be notified of every touch event. This would mean that you'd be called for every event in a single gesture (e.g., you'd be called many times for a single swipe gesture), but you could perhaps decide to react only to ACTION_DOWN
events or similar.