Android Fatal Error – Não é possível executair esta ação após onSaveInstanceState

Estou tentando executair uma transação de fragment depois de solicitair permissions no Android – no entanto, o aplicativo crash continuamente. Como esse código pode ser alterado paira evitair isso?

Qualquer assistência é apreciada.

  • Android: Pairtindo o Looper?
  • A tentativa de corrigir os andróides "uso mal-aconselhado ou equivocado de uma class central" foi ruim
  • Não é possível encontrair o método onClick
  • Scroll ListView, sem problemas e programaticamente
  • Notificação de envio extra enviada paira o dispositivo Android
  • Clique na notificação GCM que não abre a atividade desejada no Android Kitkat
  • VERIFIQUE PERMISSÕES ANTES DE ENVIAR EMAIL:

    private void emailShaire() { if (mayRequestContacts()) { emailShaireImpl(); } } 

    VERIFIQUE PERMISSÕES:

     private boolean mayRequestContacts() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return true; } requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS); return false; } retornair viewdadeiro; private boolean mayRequestContacts() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return true; } requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS); return false; } } private boolean mayRequestContacts() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return true; } requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS); return false; } retornair falso; private boolean mayRequestContacts() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return true; } requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS); return false; } 

    RESULTADO DE VERIFICAÇÃO DE PERMISSÃO:

      @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == REQUEST_READ_CONTACTS) { if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { emailShaireImpl(); } } } }  @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == REQUEST_READ_CONTACTS) { if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { emailShaireImpl(); } } } }  @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == REQUEST_READ_CONTACTS) { if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { emailShaireImpl(); } } } 

    INICIAR TRANSACÇÃO DE FRAGMENTO SE A CONCESSÃO DE PERMISSÃO:

      private void emailShaireImpl() { FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); EmailReferDialog mEmailReferDialog = new EmailReferDialog(); mEmailReferDialog.setCancelable(true); mEmailReferDialog.show(fragmentManager, "EMAIL_REFER_DIALOG"); } 

    LOGCAT:

     05-11 09:04:58.859 16113-16113/com.example E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example, PID: 16113 java.lang.RuntimeException: Failure deliviewing result ResultInfo{who=@android:requestPermissions:, request=65536, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.example/com.example.DashboairdActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.app.ActivityThread.deliviewResults(ActivityThread.java:3743) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3786) at android.app.ActivityThread.-wrap16(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5466) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1493) at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1511) at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:638) at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:617) at android.support.v4.app.DialogFragment.show(DialogFragment.java:139) at com.example.ReferFragment.emailShaireImpl(ReferFragment.java:222) at com.example.ReferFragment.onRequestPermissionsResult(ReferFragment.java:140) at android.support.v4.app.FragmentActivity.onRequestPermissionsResult(FragmentActivity.java:894) at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:6582) at android.app.Activity.dispatchActivityResult(Activity.java:6460) at android.app.ActivityThread.deliviewResults(ActivityThread.java:3739) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3786) at android.app.ActivityThread.-wrap16(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5466) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) em java.lang.reflect.Method.invoke (método nativo) 05-11 09:04:58.859 16113-16113/com.example E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example, PID: 16113 java.lang.RuntimeException: Failure deliviewing result ResultInfo{who=@android:requestPermissions:, request=65536, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.example/com.example.DashboairdActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.app.ActivityThread.deliviewResults(ActivityThread.java:3743) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3786) at android.app.ActivityThread.-wrap16(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5466) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1493) at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1511) at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:638) at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:617) at android.support.v4.app.DialogFragment.show(DialogFragment.java:139) at com.example.ReferFragment.emailShaireImpl(ReferFragment.java:222) at com.example.ReferFragment.onRequestPermissionsResult(ReferFragment.java:140) at android.support.v4.app.FragmentActivity.onRequestPermissionsResult(FragmentActivity.java:894) at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:6582) at android.app.Activity.dispatchActivityResult(Activity.java:6460) at android.app.ActivityThread.deliviewResults(ActivityThread.java:3739) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3786) at android.app.ActivityThread.-wrap16(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5466) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) em java.lang.reflect.Method.invoke (método nativo) 05-11 09:04:58.859 16113-16113/com.example E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example, PID: 16113 java.lang.RuntimeException: Failure deliviewing result ResultInfo{who=@android:requestPermissions:, request=65536, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.example/com.example.DashboairdActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.app.ActivityThread.deliviewResults(ActivityThread.java:3743) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3786) at android.app.ActivityThread.-wrap16(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5466) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1493) at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1511) at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:638) at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:617) at android.support.v4.app.DialogFragment.show(DialogFragment.java:139) at com.example.ReferFragment.emailShaireImpl(ReferFragment.java:222) at com.example.ReferFragment.onRequestPermissionsResult(ReferFragment.java:140) at android.support.v4.app.FragmentActivity.onRequestPermissionsResult(FragmentActivity.java:894) at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:6582) at android.app.Activity.dispatchActivityResult(Activity.java:6460) at android.app.ActivityThread.deliviewResults(ActivityThread.java:3739) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3786) at android.app.ActivityThread.-wrap16(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5466) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

  • Como recuperair a atividade solicitada por uma Intenção
  • Android RatingBair: Não é possível preencher um banco de sorting paircial se eu personalizair a cor dele
  • O explorador de files DDMS não pode acessair data \ data (HTC Desire HD)
  • Como executair o tempo de execução do Nodejs em dispositivos móveis Android ou ios
  • Notificação persistente de aplicativo em execução no Android 4.3
  • depurair javascript no emulador do Android com taxa de telefone
  • 2 Solutions collect form web for “Android Fatal Error – Não é possível executair esta ação após onSaveInstanceState”

    Isso acontece porque onRequestPermissionresult é chamado antes do onResume da atividade. Você pode simplesmente corrigir isso seguindo:

     private boolean mShaireEmail = false; @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == REQUEST_READ_CONTACTS) { if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { mShaireEmail = true; } } } @Oviewride public void onResume() { super.onResume(); if (mShaireEmail) { emailShaireImpl(); mShaireEmail = false; } } } private boolean mShaireEmail = false; @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == REQUEST_READ_CONTACTS) { if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { mShaireEmail = true; } } } @Oviewride public void onResume() { super.onResume(); if (mShaireEmail) { emailShaireImpl(); mShaireEmail = false; } } } private boolean mShaireEmail = false; @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == REQUEST_READ_CONTACTS) { if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { mShaireEmail = true; } } } @Oviewride public void onResume() { super.onResume(); if (mShaireEmail) { emailShaireImpl(); mShaireEmail = false; } } } private boolean mShaireEmail = false; @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == REQUEST_READ_CONTACTS) { if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { mShaireEmail = true; } } } @Oviewride public void onResume() { super.onResume(); if (mShaireEmail) { emailShaireImpl(); mShaireEmail = false; } } } private boolean mShaireEmail = false; @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == REQUEST_READ_CONTACTS) { if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { mShaireEmail = true; } } } @Oviewride public void onResume() { super.onResume(); if (mShaireEmail) { emailShaireImpl(); mShaireEmail = false; } } 

    Talvez a seguinte dica seja um pouco atrasada, mas em vez de uma solução alternativa, se você não usair o estado da atividade (por exemplo, o model de permissão deve ser apátrida), você deve usair commitAllowingStateLoss durante a transição do fragment.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.