Android 如何在应用程序首次运行时仅显示一次视图?
我想开发一个应用程序,在安装后显示一次身份验证屏幕,然后在后续运行时显示其他屏幕。有办法吗?您可以使用。像isFirstTime这样的布尔变量可以查看您的工作。您可以使用它来执行此操作。类似isFirstTime的布尔变量可以查看您的工作。使用SharedReference存储firstboot值,并根据该值检入活动。如果设置了该值,则表示之前已启动应用程序。否则,您将在SharedReference中显示活动并设置firstrun标志 例如,您启动的活动可能看起来像这样Android 如何在应用程序首次运行时仅显示一次视图?,android,Android,我想开发一个应用程序,在安装后显示一次身份验证屏幕,然后在后续运行时显示其他屏幕。有办法吗?您可以使用。像isFirstTime这样的布尔变量可以查看您的工作。您可以使用它来执行此操作。类似isFirstTime的布尔变量可以查看您的工作。使用SharedReference存储firstboot值,并根据该值检入活动。如果设置了该值,则表示之前已启动应用程序。否则,您将在SharedReference中显示活动并设置firstrun标志 例如,您启动的活动可能看起来像这样 public void
public void onCreate(){
boolean firstboot = getSharedPreference("BOOT_PREF", MODE_PRIVATE).getBoolean("firstboot", true);
if (firstboot){
// 1) Launch the authentication activity
// 2) Then save the state
getSharedPreference("BOOT_PREF", MODE_PRIVATE)
.edit()
.putBoolean("firstboot", false)
.commit();
}
}
使用SharedReference存储firstboot值,并根据该值检入活动。如果设置了该值,则表示之前已启动应用程序。否则,您将在SharedReference中显示活动并设置firstrun标志
例如,您启动的活动可能看起来像这样
public void onCreate(){
boolean firstboot = getSharedPreference("BOOT_PREF", MODE_PRIVATE).getBoolean("firstboot", true);
if (firstboot){
// 1) Launch the authentication activity
// 2) Then save the state
getSharedPreference("BOOT_PREF", MODE_PRIVATE)
.edit()
.putBoolean("firstboot", false)
.commit();
}
}
使用SharedReference可以做到这一点
清真寺
public static void saveflagmosque(){
SharedPreferences.Editor editor = sharedPref.edit();
editor.putBoolean("mosque", false);
editor.commit();
}
public boolean getflagmosque(){
flagmosque = sharedPref.getBoolean("mosque", true);
return flagmosque;
}
编码
flagmosque = true ;
if(getflagmosque()){
your task that run only one time ;
}
使用SharedReference可以做到这一点
清真寺
public static void saveflagmosque(){
SharedPreferences.Editor editor = sharedPref.edit();
editor.putBoolean("mosque", false);
editor.commit();
}
public boolean getflagmosque(){
flagmosque = sharedPref.getBoolean("mosque", true);
return flagmosque;
}
编码
flagmosque = true ;
if(getflagmosque()){
your task that run only one time ;
}
该代码放在哪里?在将显示一个时间的活动中?或者在显示下一屏幕的活动中?将此代码放在何处?在将显示一个时间的活动中?或者在显示下一个屏幕的活动中?thx我使用了它,它可以工作,但我不知道在第二次启动应用程序时如何传递到另一个活动time@emna声明其他条件。这不是一个愚蠢的问题,但是我不确定这是否是最佳实践。thx我使用了它,它也可以工作,但我不知道在第二次启动应用程序时如何传递到另一个活动time@emna这不是一个愚蠢的问题,但我不确定这是否是最佳实践。