Event trigger and transfer mechanism in Android Activity and ViewGroup, androidviewgroup
1. When only Activity is available:
1) Touch event trigger process:
First, trigger dispatchTouchEvent and then trigger onUserInteraction again. If onTouchEvent is clicked, follow the following events (Click ACTION_DOWN and ACTION_up in two steps) trigger dispatchTouchEvent again onTouchEvent when ACTION_up event does not trigger onUserInteraction (you can view the source code)
2) keyboard event triggering Process
First, trigger dispatchKeyEvent and then trigger onUserInteraction again onKeyDown. If you press and then release it, the two steps are followed to trigger the dispatchKeyEvent and then trigger onUserInteraction again onKeyUp. Note that onUserInteraction is triggered when you release the key.
In short: Activity. dispatchTouchEvent (MotionEvent)-This allows your Activity to capture all touch events before being distributed to the window. (Similarly, dispatchKeyEvent)
2. There is a Layout in the Activity and a button in Layout:
If a CLICK event is triggered on the button, the event transmission process is as follows:
First, trigger the dispatchTouchEvent of the ACTIVITY, then trigger the onUserInteraction of the ACTIVITY, then trigger the dispatchTouchEvent of LAYOUT, then trigger the onTouch (this is an ACTION_DOWN event) of the BUTTON) it is followed by the dispatchTouchEvent of the ACTIVITY triggered by an ACTION_UP event. Note that the onUserInteraction of the ACTIVITY will not be triggered because it does not work for ACTION_UP. Then, the dispatchTouchEvent of LAYOUT is triggered, the onInterceptTouchEvent of LAYOUT is triggered, the onTouch of the BUTTON is triggered, and The onClick of the BUTTON is finally triggered. if you return true in the ONTOUCH event and consume the event, The ONCLICK event will not be responded. However, if you do not write The ONCLICK event, the ONTOUCH event will return FLASE.
3. Summary:
Android event triggering process:
-------------------------------------------------------------------
First, trigger the dispatchTouchEvent of the ACTIVITY.
Then, the onUserInteraction of the ACTIVITY is triggered.
Then, the dispatchTouchEvent of LAYOUT is triggered.
Then, the onInterceptTouchEvent of LAYOUT is triggered.
-------------------------------------------------------------------