फ्रैगमेंट एपीआई जारी होने के बाद, मैंने अपने सभी बहिष्कृत संवादों को संगतता पैकेज का उपयोग करके संवादप्रवाहों में पोर्ट करना शुरू कर दिया। सब कुछ अच्छी तरह काम कर रहा था, जब तक मुझे लगता है कि मेरी संवाद केवल ICS के लिए दुर्घटनाओं का कारण बन रहे नोटिस:डायलॉगफ्रैगमेंट्स दिखा रहा है आईसीएस
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)
मेरे संवाद के क्रम में उपयोगकर्ता के लिए एक http प्रतिक्रिया दिखाने के लिए AsyncTask.onPostExecute() पर दिखाया जाता है। समस्या में डाइविंग के बाद, मुझे निष्कर्ष निकाला गया कि यह अपवाद तब होता है जब गतिविधि रोक दी जाती है या रोका जाता है, और यह एंड्रॉइड के अन्य संस्करणों पर नहीं होता है। मैंने commitAllowingStateLoss() का उपयोग करने का प्रयास किया है, लेकिन यह मदद नहीं करता है, क्योंकि अपवाद को DialogFragment.show() पर फेंक दिया गया है। डायलॉग फ्रैगमेंट के लिए मेरा कोड यहां दिया गया है:
private static void showDialog(FragmentActivity activity, String title, String msg,
String positiveButtonText, String negativeButtonText, int id, Bundle args) {
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 (args == null) {
args = new Bundle();
}
args.putString("title", title);
args.putString("message", msg);
args.putString("positiveButtonText", positiveButtonText);
args.putString("negativeButtonText", negativeButtonText);
args.putInt("id", id);
newFragment.setArguments(args);
newFragment.setCancelable(false);
newFragment.show(fmgr, TAG); // exception is thrown here
ft.commit();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Bundle args = getArguments();
String title = args.getString("title");
String msg = args.getString("message");
String positiveButtonText = args.getString("positiveButtonText");
String negativeButtonText = args.getString("negativeButtonText");
final int id = args.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, args);
}
});
builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
handler.doNegativeClick(id, args);
}
});
return builder.create();
}
क्या यह आईसीएस पर एक बग है? मुझे क्या करना चाहिए?
इसी तरह के प्रश्न और उत्तर के लिए [यहां] देखें (http://stackoverflow.com/questions/7992496/how-to-handle-asynctask-onpostexecute-when-paused-to-avoid-illegalstateexception)। – PJL