屏幕旋转时的Android ClickableSpan DialogFragment IllegalStateException

时间:2016-07-25 07:17:14

标签: android android-dialogfragment

我正在尝试在单击TextView中的某个单词时显示对话框。它工作正常,直到我旋转屏幕。日志显示已创建新跨度,但调用旧已取消的跨度onClick。我使用DialogFragment,当在对话框外触摸时将被取消。

MainActivity: in onCreate(): MainActivity@c1ad544
MyClickableSpan: in MyClickableSpan(): MainActivity@c1ad544 | MyClickableSpan@ac63b59

/* clicked the text */
MyClickableSpan: in onClick(): MainActivity@c1ad544 |  MyClickableSpan@ac63b59

/* dismissed the dialog and rotated the screen */
MainActivity: in onCreate(): MainActivity@7eb1060
MyClickableSpan: in MyClickableSpan(): MainActivity@7eb1060 | MyClickableSpan@7490811
InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
ViewRootImpl: Dropping event due to root view being removed

/* clicked the text again */
MyClickableSpan: in onClick(): MainActivity@c1ad544 | MyClickableSpan@ac63b59
E/InputEventReceiver: Exception dispatching input event.
E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
E/MessageQueue-JNI: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
        at android.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1411)

我在MainActivity的onCreate中创建一个MyClickableSpan,并将this作为上下文传递给MyClickableSpan的构造函数,以便稍后获取FragmentManager。显示对话框的代码是:

@Override
public void onClick(View widget) {
    MyDialogFragment fragment = new MyDialogFragment();
    FragmentManager fm = ((Activity)context).getFragmentManager();
    fragment.show(fm, "MyDialogFragment");
}

0 个答案:

没有答案