An application in which a user can log in. I have the following situation: if the user is logged in, perform the else action by starting the login operation for the result, and if the result is Activity.RESULT_OK, it will execute the action.
My problem is that the action to execute is to show DialogFragment but call
DialogFragment newFragment = MyDialogFragment.newInstance(mStackLevel); newFragment.show(ft, "dialog")
the onActivityResult callback throws an exception:
Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
So how can I solve this? I think I raise the flag there and show the dialog in onResume, but I see this solution a little dirty
Edit: added more code (Im following this example to show DialogFragment
When an action is requested by the user:
... if (!user.isLogged()){ startActivityForResult(new Intent(cnt, Login.class), REQUEST_LOGIN_FOR_COMMENT); }
In the same fragment
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_LOGIN_FOR_COMMENT && resultCode == Activity.RESULT_OK) { FragmentTransaction ft = getFragmentManager().beginTransaction(); DialogFragment newFragment = MyDialogFragment.newInstance(); newFragment.show(ft, "dialog") } }
And if the user logs in activity calls,
setResult(Activity.RESULT_OK); finish();
java android android-fragments
Addev Aug 24 2018-12-12T00: 00Z
source share