更新时间:2023-11-19 11:20:58
我希望这会帮助你。
logoutButton.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(查看为arg0){
共享preferences我的preFS = getShared preferences(活动,
MODE_PRIVATE);
/*AppState.getSingleInstance().setLoggingOut(true);*/
setLoginState(真正的);
Log.d(TAG,退出,进入第一个活动);
意向意图=新的意图(HomePage.this,
LoginPage.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
/ * intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK); * /
startActivity(意向);
完成()//完成这一活动
}
});
I want to clear all previous activity stack and launch new activity. But when i press back key control goes to previous activity. I am not finished all previous activity. When i logout i want to exit from app. I used below flags:
intentLogin.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intentLogin.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intentLogin.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intentLogin.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
and added below lines in AndroidManifest.xml
android:launchMode="singleInstance"
But there is white screen appears before launching new activity.
I also changed theme to Translucent but while launching activity, but it shows android home icons for some moment.
I don't want to use:
moveTaskToBack(true);
i hope this will help you
logoutButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
SharedPreferences myPrefs = getSharedPreferences("Activity",
MODE_PRIVATE);
/*AppState.getSingleInstance().setLoggingOut(true);*/
setLoginState(true);
Log.d(TAG, "log out and go to first activity");
Intent intent = new Intent(HomePage.this,
LoginPage.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
/* intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);*/
startActivity(intent);
finish() // finish this activity
}
});