用于清除共享首选项并退出的功能:
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);
清单文件:
<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" />
我的第一页FirPageflipMainActivity注册后完成前四个活动我在主要活动中有Signout按钮,当我调用给定代码删除并清除并从共享首选项值退出应用程序然后它变为退出但它在主动活动之前出现在Splash页面上虽然我想它应该从凝视页面开始,这是FirPageflipMainActivity请告诉我在哪里做错了
答案 0 :(得分:0)
在Utility类或Activity或Fragment
中创建方法resetsetSharedPreferencespublic static void resetsetSharedPreferences(Context context,
String sharedPrefname) {
SharedPreferences mPrefs = context.getSharedPreferences(sharedPrefname,
Context.MODE_PRIVATE);
mPrefs.edit().clear().commit();
}
然后在注销期间调用此方法
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);
答案 1 :(得分:0)
尝试进行这些更改:
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();
希望这有帮助。