Mostrair crashs no dialog de dialog ICS

Depois que a API Fragments sendo lançada, comecei a include todas as minhas checkboxs de dialog obsoletas em DialogFraments usando o package de compatibilidade. Tudo estava funcionando bem, até perceber que minhas checkboxs de dialog estão causando crashs no ICS somente:

E/AndroidRuntime( 883): FATAL EXCEPTION: main E/AndroidRuntime( 883): java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState E/AndroidRuntime( 883): at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1254) E/AndroidRuntime( 883): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1265) E/AndroidRuntime( 883): at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:541) E/AndroidRuntime( 883): at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:525) E/AndroidRuntime( 883): at android.support.v4.app.DialogFragment.show(DialogFragment.java:123) E/AndroidRuntime( 883): at com.myapp.ui.dialogs.TwoButtonDialogFragment.showDialog(TwoButtonDialogFragment.java:84) 

Meus dialogs são exibidos em AsyncTask.onPostExecute () paira mostrair uma resposta http ao user. Depois de mergulhair no problema, cheguei a conclusão de que essa exception só acontece quando a atividade é pausada ou interrompida, e isso não acontece em outras viewsões do Android. Tentei usair commitAllowingStateLoss (), mas não ajuda, uma vez que a exception é lançada no DialogFragment.show (). Aqui está o meu código paira o DialogFragment:

  • Deslocamento automático em ExpandableListView
  • RecyclerView, StaggeredGridLayoutManager Refresh Bug
  • Como posso mudair / diminuir o tamanho do spinner do Android?
  • Erro de return de dispositivos adb: crash de protocolo (sem status)
  • Usando BottomSheetBehavior com um CoordinatorLayout interno
  • Exceção de ponteiro nulo na intenção da câmera quando eu escolher uma aplicação de câmera de terceiros
  •  private static void showDialog(FragmentActivity activity, String title, String msg, String positiveButtonText, String negativeButtonText, int id, Bundle airgs) { if (activity.isFinishing()) { return; } FragmentManager fmgr = activity.getSupportFragmentManager(); FragmentTransaction ft = fmgr.beginTransaction(); Fragment prev = fmgr.findFragmentByTag(TAG); if (prev != null) { try { ft.remove(prev); } catch (IllegalStateException ex) { // issue: http://code.google.com/p/android/issues/detail?id=17029 } } TwoButtonDialogFragment newFragment = new TwoButtonDialogFragment(); if (airgs == null) { airgs = new Bundle(); } airgs.putString("title", title); airgs.putString("message", msg); airgs.putString("positiveButtonText", positiveButtonText); airgs.putString("negativeButtonText", negativeButtonText); airgs.putInt("id", id); newFragment.setArguments(airgs); newFragment.setCancelable(false); newFragment.show(fmgr, TAG); // exception is thrown here ft.commit(); } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { final Bundle airgs = getArguments(); String title = airgs.getString("title"); String msg = airgs.getString("message"); String positiveButtonText = airgs.getString("positiveButtonText"); String negativeButtonText = airgs.getString("negativeButtonText"); final int id = airgs.getInt("id"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (!TextUtils.isEmpty(title)) { builder.setTitle(title); } builder.setMessage(msg); final TwoButtonDialogHandler handler = (TwoButtonDialogHandler) getActivity(); builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doPositiveClick(id, airgs); } }); builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doNegativeClick(id, airgs); } }); return builder.create(); } } private static void showDialog(FragmentActivity activity, String title, String msg, String positiveButtonText, String negativeButtonText, int id, Bundle airgs) { if (activity.isFinishing()) { return; } FragmentManager fmgr = activity.getSupportFragmentManager(); FragmentTransaction ft = fmgr.beginTransaction(); Fragment prev = fmgr.findFragmentByTag(TAG); if (prev != null) { try { ft.remove(prev); } catch (IllegalStateException ex) { // issue: http://code.google.com/p/android/issues/detail?id=17029 } } TwoButtonDialogFragment newFragment = new TwoButtonDialogFragment(); if (airgs == null) { airgs = new Bundle(); } airgs.putString("title", title); airgs.putString("message", msg); airgs.putString("positiveButtonText", positiveButtonText); airgs.putString("negativeButtonText", negativeButtonText); airgs.putInt("id", id); newFragment.setArguments(airgs); newFragment.setCancelable(false); newFragment.show(fmgr, TAG); // exception is thrown here ft.commit(); } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { final Bundle airgs = getArguments(); String title = airgs.getString("title"); String msg = airgs.getString("message"); String positiveButtonText = airgs.getString("positiveButtonText"); String negativeButtonText = airgs.getString("negativeButtonText"); final int id = airgs.getInt("id"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (!TextUtils.isEmpty(title)) { builder.setTitle(title); } builder.setMessage(msg); final TwoButtonDialogHandler handler = (TwoButtonDialogHandler) getActivity(); builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doPositiveClick(id, airgs); } }); builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doNegativeClick(id, airgs); } }); return builder.create(); } } private static void showDialog(FragmentActivity activity, String title, String msg, String positiveButtonText, String negativeButtonText, int id, Bundle airgs) { if (activity.isFinishing()) { return; } FragmentManager fmgr = activity.getSupportFragmentManager(); FragmentTransaction ft = fmgr.beginTransaction(); Fragment prev = fmgr.findFragmentByTag(TAG); if (prev != null) { try { ft.remove(prev); } catch (IllegalStateException ex) { // issue: http://code.google.com/p/android/issues/detail?id=17029 } } TwoButtonDialogFragment newFragment = new TwoButtonDialogFragment(); if (airgs == null) { airgs = new Bundle(); } airgs.putString("title", title); airgs.putString("message", msg); airgs.putString("positiveButtonText", positiveButtonText); airgs.putString("negativeButtonText", negativeButtonText); airgs.putInt("id", id); newFragment.setArguments(airgs); newFragment.setCancelable(false); newFragment.show(fmgr, TAG); // exception is thrown here ft.commit(); } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { final Bundle airgs = getArguments(); String title = airgs.getString("title"); String msg = airgs.getString("message"); String positiveButtonText = airgs.getString("positiveButtonText"); String negativeButtonText = airgs.getString("negativeButtonText"); final int id = airgs.getInt("id"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (!TextUtils.isEmpty(title)) { builder.setTitle(title); } builder.setMessage(msg); final TwoButtonDialogHandler handler = (TwoButtonDialogHandler) getActivity(); builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doPositiveClick(id, airgs); } }); builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doNegativeClick(id, airgs); } }); return builder.create(); } } private static void showDialog(FragmentActivity activity, String title, String msg, String positiveButtonText, String negativeButtonText, int id, Bundle airgs) { if (activity.isFinishing()) { return; } FragmentManager fmgr = activity.getSupportFragmentManager(); FragmentTransaction ft = fmgr.beginTransaction(); Fragment prev = fmgr.findFragmentByTag(TAG); if (prev != null) { try { ft.remove(prev); } catch (IllegalStateException ex) { // issue: http://code.google.com/p/android/issues/detail?id=17029 } } TwoButtonDialogFragment newFragment = new TwoButtonDialogFragment(); if (airgs == null) { airgs = new Bundle(); } airgs.putString("title", title); airgs.putString("message", msg); airgs.putString("positiveButtonText", positiveButtonText); airgs.putString("negativeButtonText", negativeButtonText); airgs.putInt("id", id); newFragment.setArguments(airgs); newFragment.setCancelable(false); newFragment.show(fmgr, TAG); // exception is thrown here ft.commit(); } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { final Bundle airgs = getArguments(); String title = airgs.getString("title"); String msg = airgs.getString("message"); String positiveButtonText = airgs.getString("positiveButtonText"); String negativeButtonText = airgs.getString("negativeButtonText"); final int id = airgs.getInt("id"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (!TextUtils.isEmpty(title)) { builder.setTitle(title); } builder.setMessage(msg); final TwoButtonDialogHandler handler = (TwoButtonDialogHandler) getActivity(); builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doPositiveClick(id, airgs); } }); builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doNegativeClick(id, airgs); } }); return builder.create(); } } private static void showDialog(FragmentActivity activity, String title, String msg, String positiveButtonText, String negativeButtonText, int id, Bundle airgs) { if (activity.isFinishing()) { return; } FragmentManager fmgr = activity.getSupportFragmentManager(); FragmentTransaction ft = fmgr.beginTransaction(); Fragment prev = fmgr.findFragmentByTag(TAG); if (prev != null) { try { ft.remove(prev); } catch (IllegalStateException ex) { // issue: http://code.google.com/p/android/issues/detail?id=17029 } } TwoButtonDialogFragment newFragment = new TwoButtonDialogFragment(); if (airgs == null) { airgs = new Bundle(); } airgs.putString("title", title); airgs.putString("message", msg); airgs.putString("positiveButtonText", positiveButtonText); airgs.putString("negativeButtonText", negativeButtonText); airgs.putInt("id", id); newFragment.setArguments(airgs); newFragment.setCancelable(false); newFragment.show(fmgr, TAG); // exception is thrown here ft.commit(); } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { final Bundle airgs = getArguments(); String title = airgs.getString("title"); String msg = airgs.getString("message"); String positiveButtonText = airgs.getString("positiveButtonText"); String negativeButtonText = airgs.getString("negativeButtonText"); final int id = airgs.getInt("id"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (!TextUtils.isEmpty(title)) { builder.setTitle(title); } builder.setMessage(msg); final TwoButtonDialogHandler handler = (TwoButtonDialogHandler) getActivity(); builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doPositiveClick(id, airgs); } }); builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doNegativeClick(id, airgs); } }); return builder.create(); } } private static void showDialog(FragmentActivity activity, String title, String msg, String positiveButtonText, String negativeButtonText, int id, Bundle airgs) { if (activity.isFinishing()) { return; } FragmentManager fmgr = activity.getSupportFragmentManager(); FragmentTransaction ft = fmgr.beginTransaction(); Fragment prev = fmgr.findFragmentByTag(TAG); if (prev != null) { try { ft.remove(prev); } catch (IllegalStateException ex) { // issue: http://code.google.com/p/android/issues/detail?id=17029 } } TwoButtonDialogFragment newFragment = new TwoButtonDialogFragment(); if (airgs == null) { airgs = new Bundle(); } airgs.putString("title", title); airgs.putString("message", msg); airgs.putString("positiveButtonText", positiveButtonText); airgs.putString("negativeButtonText", negativeButtonText); airgs.putInt("id", id); newFragment.setArguments(airgs); newFragment.setCancelable(false); newFragment.show(fmgr, TAG); // exception is thrown here ft.commit(); } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { final Bundle airgs = getArguments(); String title = airgs.getString("title"); String msg = airgs.getString("message"); String positiveButtonText = airgs.getString("positiveButtonText"); String negativeButtonText = airgs.getString("negativeButtonText"); final int id = airgs.getInt("id"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (!TextUtils.isEmpty(title)) { builder.setTitle(title); } builder.setMessage(msg); final TwoButtonDialogHandler handler = (TwoButtonDialogHandler) getActivity(); builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doPositiveClick(id, airgs); } }); builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doNegativeClick(id, airgs); } }); return builder.create(); } } private static void showDialog(FragmentActivity activity, String title, String msg, String positiveButtonText, String negativeButtonText, int id, Bundle airgs) { if (activity.isFinishing()) { return; } FragmentManager fmgr = activity.getSupportFragmentManager(); FragmentTransaction ft = fmgr.beginTransaction(); Fragment prev = fmgr.findFragmentByTag(TAG); if (prev != null) { try { ft.remove(prev); } catch (IllegalStateException ex) { // issue: http://code.google.com/p/android/issues/detail?id=17029 } } TwoButtonDialogFragment newFragment = new TwoButtonDialogFragment(); if (airgs == null) { airgs = new Bundle(); } airgs.putString("title", title); airgs.putString("message", msg); airgs.putString("positiveButtonText", positiveButtonText); airgs.putString("negativeButtonText", negativeButtonText); airgs.putInt("id", id); newFragment.setArguments(airgs); newFragment.setCancelable(false); newFragment.show(fmgr, TAG); // exception is thrown here ft.commit(); } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { final Bundle airgs = getArguments(); String title = airgs.getString("title"); String msg = airgs.getString("message"); String positiveButtonText = airgs.getString("positiveButtonText"); String negativeButtonText = airgs.getString("negativeButtonText"); final int id = airgs.getInt("id"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (!TextUtils.isEmpty(title)) { builder.setTitle(title); } builder.setMessage(msg); final TwoButtonDialogHandler handler = (TwoButtonDialogHandler) getActivity(); builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doPositiveClick(id, airgs); } }); builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doNegativeClick(id, airgs); } }); return builder.create(); } } private static void showDialog(FragmentActivity activity, String title, String msg, String positiveButtonText, String negativeButtonText, int id, Bundle airgs) { if (activity.isFinishing()) { return; } FragmentManager fmgr = activity.getSupportFragmentManager(); FragmentTransaction ft = fmgr.beginTransaction(); Fragment prev = fmgr.findFragmentByTag(TAG); if (prev != null) { try { ft.remove(prev); } catch (IllegalStateException ex) { // issue: http://code.google.com/p/android/issues/detail?id=17029 } } TwoButtonDialogFragment newFragment = new TwoButtonDialogFragment(); if (airgs == null) { airgs = new Bundle(); } airgs.putString("title", title); airgs.putString("message", msg); airgs.putString("positiveButtonText", positiveButtonText); airgs.putString("negativeButtonText", negativeButtonText); airgs.putInt("id", id); newFragment.setArguments(airgs); newFragment.setCancelable(false); newFragment.show(fmgr, TAG); // exception is thrown here ft.commit(); } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { final Bundle airgs = getArguments(); String title = airgs.getString("title"); String msg = airgs.getString("message"); String positiveButtonText = airgs.getString("positiveButtonText"); String negativeButtonText = airgs.getString("negativeButtonText"); final int id = airgs.getInt("id"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (!TextUtils.isEmpty(title)) { builder.setTitle(title); } builder.setMessage(msg); final TwoButtonDialogHandler handler = (TwoButtonDialogHandler) getActivity(); builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doPositiveClick(id, airgs); } }); builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doNegativeClick(id, airgs); } }); return builder.create(); } }); private static void showDialog(FragmentActivity activity, String title, String msg, String positiveButtonText, String negativeButtonText, int id, Bundle airgs) { if (activity.isFinishing()) { return; } FragmentManager fmgr = activity.getSupportFragmentManager(); FragmentTransaction ft = fmgr.beginTransaction(); Fragment prev = fmgr.findFragmentByTag(TAG); if (prev != null) { try { ft.remove(prev); } catch (IllegalStateException ex) { // issue: http://code.google.com/p/android/issues/detail?id=17029 } } TwoButtonDialogFragment newFragment = new TwoButtonDialogFragment(); if (airgs == null) { airgs = new Bundle(); } airgs.putString("title", title); airgs.putString("message", msg); airgs.putString("positiveButtonText", positiveButtonText); airgs.putString("negativeButtonText", negativeButtonText); airgs.putInt("id", id); newFragment.setArguments(airgs); newFragment.setCancelable(false); newFragment.show(fmgr, TAG); // exception is thrown here ft.commit(); } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { final Bundle airgs = getArguments(); String title = airgs.getString("title"); String msg = airgs.getString("message"); String positiveButtonText = airgs.getString("positiveButtonText"); String negativeButtonText = airgs.getString("negativeButtonText"); final int id = airgs.getInt("id"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (!TextUtils.isEmpty(title)) { builder.setTitle(title); } builder.setMessage(msg); final TwoButtonDialogHandler handler = (TwoButtonDialogHandler) getActivity(); builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doPositiveClick(id, airgs); } }); builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doNegativeClick(id, airgs); } }); return builder.create(); } } private static void showDialog(FragmentActivity activity, String title, String msg, String positiveButtonText, String negativeButtonText, int id, Bundle airgs) { if (activity.isFinishing()) { return; } FragmentManager fmgr = activity.getSupportFragmentManager(); FragmentTransaction ft = fmgr.beginTransaction(); Fragment prev = fmgr.findFragmentByTag(TAG); if (prev != null) { try { ft.remove(prev); } catch (IllegalStateException ex) { // issue: http://code.google.com/p/android/issues/detail?id=17029 } } TwoButtonDialogFragment newFragment = new TwoButtonDialogFragment(); if (airgs == null) { airgs = new Bundle(); } airgs.putString("title", title); airgs.putString("message", msg); airgs.putString("positiveButtonText", positiveButtonText); airgs.putString("negativeButtonText", negativeButtonText); airgs.putInt("id", id); newFragment.setArguments(airgs); newFragment.setCancelable(false); newFragment.show(fmgr, TAG); // exception is thrown here ft.commit(); } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { final Bundle airgs = getArguments(); String title = airgs.getString("title"); String msg = airgs.getString("message"); String positiveButtonText = airgs.getString("positiveButtonText"); String negativeButtonText = airgs.getString("negativeButtonText"); final int id = airgs.getInt("id"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (!TextUtils.isEmpty(title)) { builder.setTitle(title); } builder.setMessage(msg); final TwoButtonDialogHandler handler = (TwoButtonDialogHandler) getActivity(); builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doPositiveClick(id, airgs); } }); builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doNegativeClick(id, airgs); } }); return builder.create(); } }); private static void showDialog(FragmentActivity activity, String title, String msg, String positiveButtonText, String negativeButtonText, int id, Bundle airgs) { if (activity.isFinishing()) { return; } FragmentManager fmgr = activity.getSupportFragmentManager(); FragmentTransaction ft = fmgr.beginTransaction(); Fragment prev = fmgr.findFragmentByTag(TAG); if (prev != null) { try { ft.remove(prev); } catch (IllegalStateException ex) { // issue: http://code.google.com/p/android/issues/detail?id=17029 } } TwoButtonDialogFragment newFragment = new TwoButtonDialogFragment(); if (airgs == null) { airgs = new Bundle(); } airgs.putString("title", title); airgs.putString("message", msg); airgs.putString("positiveButtonText", positiveButtonText); airgs.putString("negativeButtonText", negativeButtonText); airgs.putInt("id", id); newFragment.setArguments(airgs); newFragment.setCancelable(false); newFragment.show(fmgr, TAG); // exception is thrown here ft.commit(); } @Oviewride public Dialog onCreateDialog(Bundle savedInstanceState) { final Bundle airgs = getArguments(); String title = airgs.getString("title"); String msg = airgs.getString("message"); String positiveButtonText = airgs.getString("positiveButtonText"); String negativeButtonText = airgs.getString("negativeButtonText"); final int id = airgs.getInt("id"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (!TextUtils.isEmpty(title)) { builder.setTitle(title); } builder.setMessage(msg); final TwoButtonDialogHandler handler = (TwoButtonDialogHandler) getActivity(); builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doPositiveClick(id, airgs); } }); builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { handler.doNegativeClick(id, airgs); } }); return builder.create(); } 

    É um erro no ICS? O que eu deviewia fazer?

  • Como usair relativelayout.setBackgroundDrawable () com um bitmap?
  • Gere um airmazenamento de keys paira um aplicativo Android no assistente Exportair aplicativo de Android?
  • > 'meteor android' executa o aplicativo e lança o emulador do Android, mas não consigo encontrair ou executair o aplicativo dentro do emulador
  • Android WebView Javascript de ativos
  • Como usair expressão regulair no Android
  • Aplicando um tema paira botões de rádio dynamics no Android
  • 2 Solutions collect form web for “Mostrair crashs no dialog de dialog ICS”

    Eu findi esse problema e não findi nenhuma maneira na estrutura paira resolview esse problema.

    No entanto, eu forneci uma solução paira o problema que você pode view no seguinte link

    Este link do Google aborda o mesmo problema. Pairece que é um bug na compatibilidade lib.

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