android – 异常调度输入事件,同时调用startActivity

在StackOverflow和其他论坛上已经提出了几个相关的问题.但是,这仍然是导致,并没有解决方案对我有用.另外,我想声明我正在使用13英寸3英寸的Braun平板电脑.

按活动流程,

一个调用B活动的活动,从B调用一个带有标志FLAG_ACTIVITY_CLEAR_TOP的活动,然后在活动A到活动B的活动之后重复这个过程.下面是更详细的解释

我从一个用于更新数据库的对话框中调用我的MainActivity,如下所示,

Intent intent = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(context.getString(R.string.IS_UPDATE_DATA), true);
context.startActivity(intent);

之后我使用AsyncTask从Web服务调用更新我的数据库,并在完成更新时使用以下代码从Activity的onTouch()使用startActivity,

Intent intent = new Intent(mContext, CategoryActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);

这导致每次都崩溃,

01-29 20:21:44.631: E/InputEventReceiver(3213): Exception dispatching input event.
01-29 20:21:44.631: E/MessageQueue-JNI(3213): Exception in MessageQueue callback: handleReceiveCallback
01-29 20:21:44.651: E/MessageQueue-JNI(3213): java.lang.NullPointerException
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.os.Parcel.readException(Parcel.java:1431)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.os.Parcel.readException(Parcel.java:1379)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1892)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.app.Instrumentation.execStartActivity(Instrumentation.java:1412)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.app.Activity.startActivityForResult(Activity.java:3407)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.app.Activity.startActivityForResult(Activity.java:3368)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.app.Activity.startActivity(Activity.java:3603)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.app.Activity.startActivity(Activity.java:3571)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at com.brodos.app.storeship.MainActivity.onTouch(MainActivity.java:857)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.View.dispatchTouchEvent(View.java:7258)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2177)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1878)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2177)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1878)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2177)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1878)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2177)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1878)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2470)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1633)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.app.Activity.dispatchTouchEvent(Activity.java:2428)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2418)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.View.dispatchPointerEvent(View.java:7443)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchPointerEvent(PhoneWindow.java:2323)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3526)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3471)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4612)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4591)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4683)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.os.MessageQueue.nativePollOnce(Native Method)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.os.MessageQueue.next(MessageQueue.java:125)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.os.Looper.loop(Looper.java:124)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at android.app.ActivityThread.main(ActivityThread.java:5063)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at java.lang.reflect.Method.invokeNative(Native Method)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at java.lang.reflect.Method.invoke(Method.java:511)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-29 20:21:44.651: E/MessageQueue-JNI(3213):   at dalvik.system.NativeStart.main(Native Method)

让我知道是否有人可以指导或有解决方案.另外,如果有任何问题需要补充,请告诉我.

最佳答案 我和你的相似,解决方案是这样的:

if (savedInstanceState != null) {
    Intent mIntent = new Intent(context, SomeActivity.class);
    mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(mIntent);
    mIntent.overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
}
点赞