0

function for clear shared preference and exit :

   SharedPreferences prefs = getSharedPreferences(
                    AppConstants.LOGIN_PREFS, Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = prefs.edit();
            editor.remove( "loggedin");
            editor.remove( "regloggedin");
            editor.remove( "activationloggedin");
            editor.remove("userdetailloggedin");
            editor.clear();
            editor.commit();
            finish();

            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_HOME);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);

Manifest file :

 <activity
            android:name=".activity.FirPageflipMainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!--FirPageflipMainActivity-->

        <activity android:name=".activity.RegitsraionPage" />
        <activity android:name=".activity.ActivationCode" />
        <activity android:name=".activity.userdetail" />
        <activity android:name=".activity.SplashScreen" />
        <activity android:name=".activity.MainActivity" />
        <activity android:name=".activity.Mainactvityfortab" />
        <activity android:name=".activity.Mainactvityfortab1" />
        <activity android:name=".activity.Mainactvityfortab2" />
        <activity android:name=".activity.Mainactvityfortab3" />
        <activity android:name=".activity.Prodculistitem" />
        <activity android:name=".activity.Itemdescription" />
        <activity
            android:name=".activity.DeliverDetail"

            android:windowSoftInputMode="stateHidden" />
        <activity android:name=".activity.Serchactvity" />
        <activity android:name=".activity.FinalypaymentDetail" />
        <activity android:name=".activity.Paytm" />

        <activity android:name=".activity.ConfirmationOrder" />

my first page FirPageflipMainActivity first four actvity is finish after registration i have Signout button in main actvity when i call given code for removing and clear and exit app from shared preferences value then it becomes exit but it come on Splash page just before mainactivity while i want it should start from staring page which is FirPageflipMainActivity please tell me where am doing wrong

Abhishek
  • 1,654
  • 2
  • 18
  • 31
Mhanaz Syed
  • 229
  • 1
  • 5
  • 18

2 Answers2

2

Try making these changes:

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

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

    this.finish();

Hope this helps.

Prasad Pawar
  • 1,606
  • 1
  • 15
  • 30
0

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

public static void resetsetSharedPreferences(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 = new Intent(getApplicationContext(), FirPageflipMainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 
    startActivity(intent);
Pavan Bilagi
  • 1,618
  • 1
  • 18
  • 23
  • i am calling both same as function http://paste.ofcode.org/pFxvFnS5Aj7Hq6FUveNXer i am callling alert to ask so please edit in this funcation – Mhanaz Syed Dec 12 '15 at 07:11