如何显示警报只在我的应用程序的第一个运行对话框? [英] How do I show an alert dialog only on the first run of my application?
本文介绍了如何显示警报只在我的应用程序的第一个运行对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我想要启动应用程序在第一次之后,显示仅在第一次警报。
I have an alert that I want to display only the first time right after starting the application for the first time.
我怎么能这样做?
推荐答案
有几个方法可以做到这一点,但也许最简单的是只是为了检查一个标志在共享preferences对象并设定它一旦警报被示出。
There are a few ways to do this, but perhaps the easiest is just to check a flag in a SharedPreferences object and set it once the alert is shown.
<一个href="http://developer.android.com/guide/topics/data/data-storage.html#$p$pf">Shared$p$pferences
类似于
public class MyActivity extends Activity {
public static final String PREFS_NAME = "MyPrefsFile";
@Override
protected void onCreate(Bundle state){
super.onCreate(state);
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean dialogShown = settings.getBoolean("dialogShown", false);
if (!dialogShown) {
// AlertDialog code here
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("dialogShown", true);
editor.commit();
}
}
这篇关于如何显示警报只在我的应用程序的第一个运行对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文