Skip to content Skip to sidebar Skip to footer

How To Delete Sharedpreferences ,quit And Launch Application From First Actvity In Android

function for clear shared preference and exit : SharedPreferences prefs = getSharedPreferences( AppConstants.LOGIN_PREFS, Context.MODE_PRIVATE);

Solution 1:

Try making these changes:

SharedPreferencesprefs= getSharedPreferences(
                    AppConstants.LOGIN_PREFS, Context.MODE_PRIVATE);
    SharedPreferences.Editoreditor= prefs.edit();
    editor.clear();
    editor.commit();

    Intentintent=newIntent(getApplicationContext(), FirPageflipMainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);

    this.finish();

Hope this helps.

Solution 2:

Create a method resetsetSharedPreferences in your Utility class or Activity or Fragment

publicstaticvoidresetsetSharedPreferences(Context context,
                                                 String sharedPrefname) {
        SharedPreferences mPrefs = context.getSharedPreferences(sharedPrefname,
                Context.MODE_PRIVATE);
        mPrefs.edit().clear().commit();
    }

And then just call to this method during signout

resetsetSharedPreferences(getActivity().getApplicationContext(), AppConstants.LOGIN_PREFS);

 Intent intent = newIntent(getApplicationContext(), FirPageflipMainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 
    startActivity(intent);

Post a Comment for "How To Delete Sharedpreferences ,quit And Launch Application From First Actvity In Android"