<legend id='FtERl'><style id='FtERl'><dir id='FtERl'><q id='FtERl'></q></dir></style></legend>
  • <tfoot id='FtERl'></tfoot>
  • <small id='FtERl'></small><noframes id='FtERl'>

    <i id='FtERl'><tr id='FtERl'><dt id='FtERl'><q id='FtERl'><span id='FtERl'><b id='FtERl'><form id='FtERl'><ins id='FtERl'></ins><ul id='FtERl'></ul><sub id='FtERl'></sub></form><legend id='FtERl'></legend><bdo id='FtERl'><pre id='FtERl'><center id='FtERl'></center></pre></bdo></b><th id='FtERl'></th></span></q></dt></tr></i><div id='FtERl'><tfoot id='FtERl'></tfoot><dl id='FtERl'><fieldset id='FtERl'></fieldset></dl></div>

          <bdo id='FtERl'></bdo><ul id='FtERl'></ul>

        在显示对话框时,我得到“在 onSaveInstanceState 之

        时间:2023-08-31
          <tbody id='Hk3Of'></tbody>

        <small id='Hk3Of'></small><noframes id='Hk3Of'>

        <tfoot id='Hk3Of'></tfoot>

          <legend id='Hk3Of'><style id='Hk3Of'><dir id='Hk3Of'><q id='Hk3Of'></q></dir></style></legend>
          <i id='Hk3Of'><tr id='Hk3Of'><dt id='Hk3Of'><q id='Hk3Of'><span id='Hk3Of'><b id='Hk3Of'><form id='Hk3Of'><ins id='Hk3Of'></ins><ul id='Hk3Of'></ul><sub id='Hk3Of'></sub></form><legend id='Hk3Of'></legend><bdo id='Hk3Of'><pre id='Hk3Of'><center id='Hk3Of'></center></pre></bdo></b><th id='Hk3Of'></th></span></q></dt></tr></i><div id='Hk3Of'><tfoot id='Hk3Of'></tfoot><dl id='Hk3Of'><fieldset id='Hk3Of'></fieldset></dl></div>

            • <bdo id='Hk3Of'></bdo><ul id='Hk3Of'></ul>

                  本文介绍了在显示对话框时,我得到“在 onSaveInstanceState 之后无法执行此操作";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  有些用户在举报,如果他们使用通知栏中的快速操作,他们会被强制关闭.

                  Some users are reporting, if they use the quick action in the notification bar, they are getting a force close.

                  我在调用 "TestDialog" 类的通知中显示了一个快速操作.在 TestDialog 类中按下贪睡"按钮后,我将显示贪睡对话框.

                  I show a quick action in the notification who calls the "TestDialog" class. In the TestDialog class after pressing the button "snooze", I will show the SnoozeDialog.

                  private View.OnClickListener btnSnoozeOnClick() {
                      return new View.OnClickListener() {
                  
                          public void onClick(View v) {
                              showSnoozeDialog();
                          }
                      };
                  }
                  
                  private void showSnoozeDialog() {
                      FragmentManager fm = getSupportFragmentManager();
                      SnoozeDialog snoozeDialog = new SnoozeDialog();
                      snoozeDialog.show(fm, "snooze_dialog");
                  }
                  

                  错误是*IllegalStateException: Can not perform this action after onSaveInstanceState*.

                  触发 IllegarStateException 的代码行是:

                  snoozeDialog.show(fm, "snooze_dialog");
                  

                  该类正在扩展FragmentActivity",而SnoozeDialog"类正在扩展DialogFragment".

                  The class is extending "FragmentActivity" and the "SnoozeDialog" class is extending "DialogFragment".

                  这是错误的完整堆栈跟踪:

                  java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
                  at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1327)
                  at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1338)
                  at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
                  at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
                  at android.support.v4.app.DialogFragment.show(DialogFragment.java:127)
                  at com.test.testing.TestDialog.f(TestDialog.java:538)
                  at com.test.testing.TestDialog.e(TestDialog.java:524)
                  at com.test.testing.TestDialog.d(TestDialog.java:519)
                  at com.test.testing.g.onClick(TestDialog.java:648)
                  at android.view.View.performClick(View.java:3620)
                  at android.view.View$PerformClick.run(View.java:14292)
                  at android.os.Handler.handleCallback(Handler.java:605)
                  at android.os.Handler.dispatchMessage(Handler.java:92)
                  at android.os.Looper.loop(Looper.java:137)
                  at android.app.ActivityThread.main(ActivityThread.java:4507)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:511)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
                  at dalvik.system.NativeStart.main(Native Method)
                  

                  我无法重现此错误,但我收到了很多错误报告.

                  I can't reproduce this error, but I am getting a lot of error reports.

                  谁能帮我解决这个错误?

                  Can anybody help that how can I fix this error?

                  推荐答案

                  这很常见 问题.我们通过在 DialogFragment 扩展类中重写 show() 和处理异常解决了这个问题

                  This is common issue. We solved this issue by overriding show() and handling exception in DialogFragment extended class

                  public class CustomDialogFragment extends DialogFragment {
                  
                      @Override
                      public void show(FragmentManager manager, String tag) {
                          try {
                              FragmentTransaction ft = manager.beginTransaction();
                              ft.add(this, tag);
                              ft.commit();
                          } catch (IllegalStateException e) {
                              Log.d("ABSDIALOGFRAG", "Exception", e);
                          }
                      }
                  }
                  

                  请注意,应用此方法不会改变 DialogFragment.class 的内部字段:

                  Note that applying this method will not alter the internal fields of the DialogFragment.class:

                  boolean mDismissed;
                  boolean mShownByMe;
                  

                  在某些情况下,这可能会导致意外结果.最好使用 commitAllowingStateLoss() 而不是 commit()

                  This may lead to unexpected results in some cases. Better use commitAllowingStateLoss() instead of commit()

                  这篇关于在显示对话框时,我得到“在 onSaveInstanceState 之后无法执行此操作";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:调用android对话框而不褪色背景 下一篇:Android - 如何在本机屏幕上显示对话框?

                  相关文章

                  最新文章

                1. <tfoot id='5lhZU'></tfoot>
                      <bdo id='5lhZU'></bdo><ul id='5lhZU'></ul>

                  1. <legend id='5lhZU'><style id='5lhZU'><dir id='5lhZU'><q id='5lhZU'></q></dir></style></legend>

                      <small id='5lhZU'></small><noframes id='5lhZU'>

                      <i id='5lhZU'><tr id='5lhZU'><dt id='5lhZU'><q id='5lhZU'><span id='5lhZU'><b id='5lhZU'><form id='5lhZU'><ins id='5lhZU'></ins><ul id='5lhZU'></ul><sub id='5lhZU'></sub></form><legend id='5lhZU'></legend><bdo id='5lhZU'><pre id='5lhZU'><center id='5lhZU'></center></pre></bdo></b><th id='5lhZU'></th></span></q></dt></tr></i><div id='5lhZU'><tfoot id='5lhZU'></tfoot><dl id='5lhZU'><fieldset id='5lhZU'></fieldset></dl></div>