Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 92e2b4f4 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Avoid re-creating a user when activity is resumed

onCreate() was getting called again, resulting in another user being
created. Keeping the new userid across pause/resume.

Change-Id: Id7930227895e95a60a77efddf361ab9408a8f797
parent cf033092
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -90,6 +90,11 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
        mIPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
        mUm = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);

        if (icicle != null && icicle.containsKey(EXTRA_USER_ID)) {
            mUserId = icicle.getInt(EXTRA_USER_ID);
            mNewUser = false;
        }

        if (mUserId == -1) {
            mUserId = mUm.createUser(getString(R.string.user_new_user_name), 0).id;
        }
@@ -111,6 +116,12 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt(EXTRA_USER_ID, mUserId);
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        if (mUserId == 0) {