Event triggering and delivery mechanism in Android Activity and ViewGroup

Source: Internet
Author: User

1. In the case of activity only:

1) Touch Event Trigger process:

First trigger dispatchtouchevent then trigger onuserinteraction again ontouchevent if it is clicked, follow the following events (click on two steps, ACTION_DOWN,ACTION_UP) Trigger Dispatchtouchevent again Ontouchevent when ACTION_UP event does not trigger Onuserinteraction (viewable source code)

2) Keyboard event triggering process

First trigger the dispatchkeyevent and then trigger onuserinteraction again onkeydown if the press is immediately released, The two steps are followed by triggering the dispatchkeyevent and then triggering onuserinteraction again onkeyup Note that unlike the touch, the onuserinteraction will also trigger when the button is released.

In summary: Activity.dispatchtouchevent (motionevent)-This allows your activity to capture all touch events before being distributed to the window. (similarly dispatchkeyevent)

There is a layout in 2.Activity with a button in layout:

If a click event is triggered on the button, then the event delivery process:

The activity's dispatchtouchevent is triggered first and then the activity's onuserinteraction is triggered and then the dispatchtouchevent of the layout is triggered and the layout onintercepttoucheven T then triggers the button's Ontouch (which is a Action_down event) followed by a action_ The UP event triggers activity's dispatchtouchevent attention no longer triggers activity's onuserinteraction, because he does not work on action_up. Then the dispatchtouchevent of layout is triggered and then the onintercepttouchevent of the layout is triggered and then the Ontouch of the button is triggered to trigger the onclick of the button. If you return true in the Ontouch event , the onclick will not be responded to if you consume this event, but if you do not write the onclick event, the Ontouch event returns flase

3. Summary:

Android Event triggering process:

-------------------------------------------------------------------

The dispatchtouchevent that triggers activity first

And then trigger the activity onuserinteraction.

Then trigger the layout of the Dispatchtouchevent

Then trigger the layout of the Onintercepttouchevent

-------------------------------------------------------------------

  

  

  

Event triggering and delivery mechanism in Android Activity and ViewGroup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.