savedInstanceState error in onRestart in Android app
<p>I am trying to show a login dialog fragment in the onRestart method of Activity. The same code works when called from onCreate and when called from a menu click listener. But when it's called from the onRestart method I get: "Can not perform this action after onSaveInstanceState." The error is happening on the DialogFragment's "show" method. I can call the newInstance method without a problem; just can't show it! Thanks for any light that can be shed...</p>

<pre><code>@Override
    protected void onRestart() {
        super.onRestart();
        if(is_logged==false) {
            showSplashDialog();
        }
        else {
            mContext.startActivity(new Intent(mContext, MenuActivity.class));
            SplashActivity.this.finish();
        }
    }
</code></pre>

<p>now the showSplashDialog method:</p>

<pre><code>public void showSplashDialog() {
            // Create the fragment and show it as a dialog.
        DialogFragment newFragment = (DialogFragment)getSupportFragmentManager().findFragmentByTag("dialog");
        if (newFragment==null) { 
            newFragment = SplashActivityDialogFragment.newInstance(LOGIN_DIALOG_ID);
            Log.d(DEBUG_TAG,"newFragment==null");
        }
        else {
            Log.d(DEBUG_TAG,"newFragment NOT null");
        }
        if(newFragment.isAdded()!=true) {
            Log.d(DEBUG_TAG,"newFragment is NOT visible");
            newFragment.show(getSupportFragmentManager(), "dialog");
        }
        else {
            Log.d(DEBUG_TAG,"newFragment IS visible");
        }  
    }
</code></pre>

<p>and the DialogFragment code:</p>

<pre><code>public static class SplashActivityDialogFragment extends DialogFragment {
        static SplashActivityDialogFragment newInstance(int whichDialog) {
            SplashActivityDialogFragment f = new SplashActivityDialogFragment();

            Bundle args = new Bundle();
            args.putInt("dialog_id", whichDialog);
            f.setArguments(args);

            return f;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            int dialog_id = getArguments().getInt("dialog_id");
            View v = null;

            switch (dialog_id) {
            case 0:
                v = inflater.inflate(R.layout.credentials_dialog, container, true);
                final EditText p = (EditText) v.findViewById(R.id.EditText_Pwd);
                final EditText u = (EditText) v.findViewById(R.id.EditText_Username);
                final TextView problem_text = (TextView) v.findViewById(R.id.TextView_ValidationProblem);

                if(((SplashActivity)getActivity()).LOGIN_MESSAGE_TYPE!=LOGIN_NO_MESSAGE_ID){
                    if(((SplashActivity)getActivity()).LOGIN_MESSAGE_TYPE==LOGIN_FAILED_ID) {
                        problem_text.setText(R.string.settings_failed_credentials);
                    }
                    else {
                        problem_text.setText(R.string.settings_failed_connection);
                    }
                    ((SplashActivity)getActivity()).LOGIN_MESSAGE_TYPE=LOGIN_NO_MESSAGE_ID;
                    problem_text.setVisibility(View.VISIBLE);
                }
                else {
                    problem_text.setVisibility(View.INVISIBLE);
                }

                getDialog().setTitle(R.string.dialog_title_login);
                Button btn_login = (Button) v.findViewById(R.id.Button_Login);
                btn_login.setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {
                        String[] params = new String[2];
                        String username="";
                        String password="";

                        username = u.getText().toString();
                        password = p.getText().toString();

                        params[0] = username;
                        params[1] = password;
                        ((SplashActivity)getActivity()).doLoginTask(params);
                        getDialog().dismiss();
                    }
                });

                Button btn_cancel = (Button)v.findViewById(R.id.Button_Cancel);
                btn_cancel.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        ((SplashActivity)getActivity()).onCancelLogin();
                        getDialog().dismiss();
                    }
                });
                return v;
            }
            return v;
        }
    }
</code></pre>
