我的应用程序有两个活动MAIN
和LOGIN
.
MAIN
我的应用程序的工作流程如下launcher
MAIN - If user logged in, show MAIN
MAIN - If user NOT logged in, show LOGIN and close finish MAIN
下面是一个可以正常工作的场景。
User launches the app -> sees LOGIN screen
User logs in, sees the MAIN screen
User presses back button on phone, sees the phone's screen again (NOT the LOGIN screen again)
下面是一个不能正常工作的场景。
User launches the app -> sees LOGIN screen
Presses middle button on the phone to send app to background
User launches the app again -> sees the LOGIN screen (here another instance of the login screen is being created...)
User logs in, sees the MAIN screen
User presses back button on phone, sees the LOGIN screen again!
我该如何解决这种情况,这样无论手机上的中间按钮是否按下,总是只有一个登录屏幕实例?
这是我的代码:
主要的
@Override
public void onStop() {
super.onStop();
finish();
}
if (TextUtils.isEmpty(authToken)) {
Intent login = new Intent(getApplicationContext(), LoginActivity.class);
startActivityForResult(login, LOGIN_ACTIVITY);
finish();
}
登录
mAccountManager.addAccountExplicitly(account, accountPassword, null);
mAccountManager.setAuthToken(account, authtokenType, authtoken);
mAccountManager.setPassword(account, accountPassword);
startActivity(new Intent(getApplicationContext(), MainActivity.class));
更新