如何让我的对话框在我的 Android 应用安装到设备上后只出现一次?
最佳答案
使用 SharedPreference 存储 firstrun
值,并根据该值检查您的启动 Activity 。如果设置了该值,则无需显示对话框。如果不是,则显示对话框并将 firstrun
标志保存在 SharedPreference 中。
例如(在您的启动 Activity 中):
public void onCreate(){
boolean firstrun = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getBoolean("firstrun", true);
if (firstrun){
//... Display the dialog message here ...
// Save the state
getSharedPreferences("PREFERENCE", MODE_PRIVATE)
.edit()
.putBoolean("firstrun", false)
.commit();
}
}
关于android - 想要在安装应用程序后仅显示一次对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5879013/