Activity的dispatchTouchEvent调用堆栈
Posted mohoward
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Activity的dispatchTouchEvent调用堆栈相关的知识,希望对你有一定的参考价值。
Activity.java的 dispatchTouchEvent
java.lang.Exception
at android.app.Activity.dispatchTouchEvent(Activity.java:4122)
at com.cultraview.whiteboard.view.MainWbActivity.dispatchTouchEvent(MainWbActivity.kt:721)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:446)
at android.view.View.dispatchPointerEvent(View.java:14568)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:6022)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5825)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5316)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5373)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5339)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5491)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5347)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5548)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5320)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5373)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5339)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5347)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5320)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:8086)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:8037)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7998)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:8209)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:221)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:335)
at android.os.Looper.loop(Looper.java:183)
at android.app.ActivityThread.main(ActivityThread.java:7664)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)
InputEventReceiver.java的 finishInputEvent
java.lang.Exception
at android.view.InputEventReceiver.finishInputEvent(InputEventReceiver.java:167)
at android.view.ViewRootImpl.finishInputEvent(ViewRootImpl.java:8115)
at android.view.ViewRootImpl.access$1900(ViewRootImpl.java:194)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5375)
at android.view.ViewRootImpl$SyntheticInputStage.onDeliverToNext(ViewRootImpl.java:6201)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5339)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5309)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5373)
at android.view.ViewRootImpl$ViewPostImeInputStage.onDeliverToNext(ViewRootImpl.java:5843)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5339)
at android.view.ViewRootImpl$InputStage.finish(ViewRootImpl.java:5332)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5349)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5320)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5373)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5339)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5491)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5347)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5548)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5320)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5373)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5339)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5347)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5320)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:8086)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:8037)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7998)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:8209)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:221)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:335)
at android.os.Looper.loop(Looper.java:183)
at android.app.ActivityThread.main(ActivityThread.java:7664)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)
仿微信滑动退出Activity
原文链接:http://blog.csdn.net/u013045971/article/details/53900820
效果图:
原理:
原理一句话就能描述清楚。重写Activity的dispatchTouchEvent,滑动的时候拿到Activity栈中栈顶Activity的上一个Acticity的ContentView添加到栈顶Activity的DecorView中,滑动的过程中做视图平移,滑动结束之后把前面拿过来用的ContentView归还给上一个Activity,然后finish当前Activity。
ActivityStack:
实现 Application.ActivityLifecycleCallbacks 接口,在App的Application中注册这个栈,当App中的Activity新增或者删除时会回调接口中的方法。
public class ActivityBackStack implements Application.ActivityLifecycleCallbacks
private Stack<Activity> mActivityStack;
public ActivityBackStack()
mActivityStack = new Stack<>();
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState)
mActivityStack.add(activity);
@Override
public void onActivityStarted(Activity activity)
@Override
public void onActivityResumed(Activity activity)
@Override
public void onActivityPaused(Activity activity)
@Override
public void onActivityStopped(Activity activity)
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState)
@Override
public void onActivityDestroyed(Activity activity)
if (activity != null)
mActivityStack.remove(activity);
/**
* 获取栈顶的Activity
*
* @return
*/
public Activity getLastActivity()
return mActivityStack.lastElement();
/**
* 获取倒数第二个Activity
*
* @return
*/
public Activity getPreActivty()
int size = mActivityStack.size();
if (size < 2)
return null;
return mActivityStack.get(size - 2);
public int getSize()
return mActivityStack.size();
然后在Application中注册这个实现类
registerActivityLifecycleCallbacks(mBackStack);
DecorView:
1.DecorView 为整个Window界面的最顶层View
2.DecorView只有一个子View LinearLayout,代表整个Window界面,包括ton通知栏,标题栏,和内容区域。
3.获取DecorView:activity.getWindow().getDecorView()
滑动:
重写Activity的dispatchTouchEvent,设定一个阀值,在阀值内出发时拿到上一个Activity的ContentView添加到当前的DecorView中,index为0,置于最低定。滑动的过程中动态改变容器的X值,让其做出平移效果,松开手之后做取消或者关闭动画。动画结束后把前面拿到的ContentView归还。
DEMO:
https://github.com/gumingwei/SwipeBackActivity
原文链接:
原文链接:http://blog.csdn.net/u013045971/article/details/53900820
以上是关于Activity的dispatchTouchEvent调用堆栈的主要内容,如果未能解决你的问题,请参考以下文章