使 start activity 只运行一次
Making start activity that only runs once
我正在尝试制作一个 activity 首先启动,一旦完成,就不会再在应用程序中加载。
实际上是activity输入主密码,主密码会保存在经典登录界面。
我在 Whosebug 上看到过类似的问题,但我没能解决问题,这里有点新手。
如果您也可以 post 代码示例,那就太好了!谢谢!
所有你必须这样检查
SharedPreferences prefs = getSharedPreferences("mySHaredpref", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
boolean isFirst = prefs.getBoolean("isfirstTime", true);
if(isFirst) {
Intent intent = new Intent(this, YourActivityName.class);
editor.putBoolean(KEY_IS_FIRST_TIME, false);
editor.commit();
startActivity(intent);
}
else{
// condition
}
我正在尝试制作一个 activity 首先启动,一旦完成,就不会再在应用程序中加载。 实际上是activity输入主密码,主密码会保存在经典登录界面。 我在 Whosebug 上看到过类似的问题,但我没能解决问题,这里有点新手。 如果您也可以 post 代码示例,那就太好了!谢谢!
所有你必须这样检查
SharedPreferences prefs = getSharedPreferences("mySHaredpref", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
boolean isFirst = prefs.getBoolean("isfirstTime", true);
if(isFirst) {
Intent intent = new Intent(this, YourActivityName.class);
editor.putBoolean(KEY_IS_FIRST_TIME, false);
editor.commit();
startActivity(intent);
}
else{
// condition
}