Note that there are some explanatory texts on larger screens.

plurals
  1. POActions in onActivityResult and "Error Can not perform this action after onSaveInstanceState"
    primarykey
    data
    text
    <p>Implementing an app where the user can log in I have the following situation: If the user is logged in perform the action else start the login activity for result and if the result is Activity.RESULT_OK do the action.</p> <p>My problem is that the action to perfom is to show a DialogFragment, but calling </p> <pre><code>DialogFragment newFragment = MyDialogFragment.newInstance(mStackLevel); newFragment.show(ft, "dialog") </code></pre> <p>in the onActivityResult callback throws an exception: </p> <pre><code>Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState </code></pre> <p>So how can I solve this? I'm thinking in raising a flag there and show the dialog in the onResume but I see this solution a little dirty</p> <p>Edit: Added more code (Im following this example for showing the <a href="http://developer.android.com/reference/android/app/DialogFragment.html">DialogFragment</a> </p> <p>When the action is requested by the user:</p> <pre><code>... if (!user.isLogged()){ startActivityForResult(new Intent(cnt, Login.class), REQUEST_LOGIN_FOR_COMMENT); } </code></pre> <p>In the same fragment</p> <pre><code>@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_LOGIN_FOR_COMMENT &amp;&amp; resultCode == Activity.RESULT_OK) { FragmentTransaction ft = getFragmentManager().beginTransaction(); DialogFragment newFragment = MyDialogFragment.newInstance(); newFragment.show(ft, "dialog") } } </code></pre> <p>And if the user logs in the Login activity calls;</p> <pre><code>setResult(Activity.RESULT_OK); finish(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload