我已经使用SharedPreferences
. 我这样做了:
LoginActivity
SharedPreferences settings;
public void onCreate(Bundle b) {
super.onCreate(b);
settings = getSharedPreferences("mySharedPref", 0);
if (settings.getBoolean("connected", false)) {
/* The user has already login, so start the dashboard */
startActivity(new Intent(getApplicationContext(), DashBoardActivity.class));
}
/* Put here the login UI */
}
...
public void doLogin() {
/* ... check credentials and another stuff ... */
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("connected", true);
editor.commit();
}
在您DashBoardActivity
覆盖该onBackPressed
方法。这会将您从DashBoardActivity
主屏幕带到您的主屏幕。
@Override
public void onBackPressed() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
}
希望能帮助到你。