0
我的应用程序打开MainActivity
,但实际上我想在应用程序启动时打开LoginActivity
。我试着像一些解决方案:每次启动应用程序时开始活动
PackageInfo info = null;
try {
info = getPackageManager().getPackageInfo(PACKAGE_NAME, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
int currentVersion = info.versionCode;
this.versionName = info.versionName;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
int lastVersion = prefs.getInt("version_code", 0);
if (currentVersion > lastVersion) {
prefs.edit().putInt("version_code", currentVersion).apply();
startActivity(new Intent(ScheduleActivity.this, LoginActivity.class));
}
而且
boolean firstboot = getSharedPreferences("BOOT_PREF",MODE_PRIVATE)
.getBoolean("firstboot", true);
if(firstboot) {
//place your code that will run single time
startActivity(new Intent(ScheduleActivity.this, LoginActivity.class));
getSharedPreferences("BOOT_PREF", MODE_PRIVATE).edit().
putBoolean("firstboot", false)
.commit();
}
所以,当我打开我的应用程序MainActivtiy默认情况下打开但我想将其更改为LoginActivity。 –