I have the following code in my onActivityResult for a fragment of mine:
onActivityResult(int requestCode, int resultCode, Intent data){ //other code ProgressFragment progFragment = new ProgressFragment(); progFragment.show(getActivity().getSupportFragmentManager(), PROG_DIALOG_TAG); // other code }
However, I'm getting the following error:
Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
Anybody know what's going on, or how I can fix this? I should note I'm using the Android Support Package.
To get the result in your fragment make sure you call startActivityForResult(intent,111); instead of getActivity(). startActivityForResult(intent,111); inside your fragment. @StErMi Make sure you call startActivityForResult() and not getActivity().
There is a DialogFragment ( SettingsBackImageDialog ) opens by click on button in Fragment ( TrainerSettings ) in MainActivity. In SettingsBackImageDialog are some buttons, one of them is for take picture and set it for Imageview ( trainersettingsmainicon ) in Fragment.
To create a DialogFragment , first create a class that extends DialogFragment , and override onCreateDialog() , as shown in the following example. Similar to how onCreateView() should create a root View in an ordinary fragment, onCreateDialog() should create a Dialog to display as part of the DialogFragment .
Dialog: A dialog is a small window that prompts the user to make a decision or enter additional information. DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs.
If you use Android support library, onResume method isn't the right place, where to play with fragments. You should do it in onResumeFragments method, see onResume method description: http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html#onResume%28%29
So the correct code from my point of view should be:
private boolean mShowDialog = false; @Override protected void onActivityResult(int requestCode, int resultCode, Intent data){ super.onActivityResult(requestCode, resultCode, data); // remember that dialog should be shown mShowDialog = true; } @Override protected void onResumeFragments() { super.onResumeFragments(); // play with fragments here if (mShowDialog) { mShowDialog = false; // Show only if is necessary, otherwise FragmentManager will take care if (getSupportFragmentManager().findFragmentByTag(PROG_DIALOG_TAG) == null) { new ProgressFragment().show(getSupportFragmentManager(), PROG_DIALOG_TAG); } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With