安卓按键事件

参考链接:https://gist.github.com/jieyu/4262418

dispatchTouchEvent:23, MainActivity (com.example.viewroot)

dispatchTouchEvent:69, WindowCallbackWrapper (android.support.v7.view)

dispatchTouchEvent:398, DecorView (com.android.internal.policy)

dispatchPointerEvent:12752, View (android.view)

processPointerEvent:5106, ViewRootImpl$ViewPostImeInputStage (android.view)

onProcess:4909, ViewRootImpl$ViewPostImeInputStage (android.view)

deliver:4426, ViewRootImpl$InputStage (android.view)

onDeliverToNext:4479, ViewRootImpl$InputStage (android.view)

forward:4445, ViewRootImpl$InputStage (android.view)

forward:4585, ViewRootImpl$AsyncInputStage (android.view)

apply:4453, ViewRootImpl$InputStage (android.view)

apply:4642, ViewRootImpl$AsyncInputStage (android.view)

deliver:4426, ViewRootImpl$InputStage (android.view)

onDeliverToNext:4479, ViewRootImpl$InputStage (android.view)

forward:4445, ViewRootImpl$InputStage (android.view)

apply:4453, ViewRootImpl$InputStage (android.view)

deliver:4426, ViewRootImpl$InputStage (android.view)

deliverInputEvent:7092, ViewRootImpl (android.view)

doProcessInputEvents:7061, ViewRootImpl (android.view)

enqueueInputEvent:7022, ViewRootImpl (android.view)

onInputEvent:7195, ViewRootImpl$WindowInputEventReceiver (android.view)

dispatchInputEvent:186, InputEventReceiver (android.view)

nativePollOnce:-1, MessageQueue (android.os)

next:326, MessageQueue (android.os)

loop:160, Looper (android.os)

main:6669, ActivityThread (android.app)

invoke:-1, Method (java.lang.reflect)

run:493, RuntimeInit$MethodAndArgsCaller (com.android.internal.os)

main:858, ZygoteInit (com.android.internal.os)


安卓的事件传递过程,如上所示,

通过native的方式,直接调用java代码进行分发事件,不经过Handler进行处理的消息;mMessageQueue = looper.getQueue();

//这里直接初始化一个c++调用java的nativie的方法,

mReceiverPtr =nativeInit(new WeakReference(this),inputChannel,mMessageQueue);


InputEventReceiver 的初始化过程,这个对象在ViewRootImpl中被初始化的,直接

:69, InputEventReceiver (android.view)

:7190, ViewRootImpl$WindowInputEventReceiver (android.view)

setView:847, ViewRootImpl (android.view)

addView:356, WindowManagerGlobal (android.view)

addView:93, WindowManagerImpl (android.view)

handleResumeActivity:3868, ActivityThread (android.app)

execute:51, ResumeActivityItem (android.app.servertransaction)

executeLifecycleState:145, TransactionExecutor (android.app.servertransaction)

execute:70, TransactionExecutor (android.app.servertransaction)

handleMessage:1808, ActivityThread$H (android.app)

dispatchMessage:106, Handler (android.os)

loop:193, Looper (android.os)

main:6669, ActivityThread (android.app)

invoke:-1, Method (java.lang.reflect)

run:493, RuntimeInit$MethodAndArgsCaller (com.android.internal.os)

main:858, ZygoteInit (com.android.internal.os)

For each application, a ViewRootImpl object is created to handle communications with the remote system WindowManagerService object. The communication is through a Linux pipe which is encapsulated in an InputChannel object (mInputChannel field in class ViewRootImpl). The ViewRootImpl object also registers an instance of InputEventReceiver when the first View object is registered with it.

你可能感兴趣的:(安卓按键事件)