Android的:首先运行弹出的对话框 [英] Android: First run popup dialog

查看:160
本文介绍了Android的:首先运行弹出的对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个弹出对话框,应用程序的第一个,这将提醒在应用程序的新变化,用户运行后显示。所以,我有一个对话框弹出这样的:

I am trying to make a popup dialog that only shows after the app's first run that will alert users of the new changes in the app. So I have a dialog popup like this:

new AlertDialog.Builder(this).setTitle("First Run").setMessage("This only pops up once").setNeutralButton("OK", null).show();

在他们关闭它,它不会回来,直到下一次更新或重新安装这些应用程序。

Once they dismiss it, it won't come back until the next update or they reinstall the app.

如何设置对话框code以上只运行一次?

How can I set the dialog code above to run only once?

推荐答案

使用<一个href="http://developer.android.com/reference/android/content/Shared$p$pferences.html">Shared$p$pferences存储在isfirstRun 的价值,并为您在针对该值的发射活动。

Use SharedPreferences to store the isFirstRun value, and check in your launching activity against that value.

如果该值被设置,则没有必要显示对话框。如果其他人,显示对话框并保存在isfirstRun 标志中共享preferences。

If the value is set, then no need to display the dialog. If else, display the dialog and save the isFirstRun flag in SharedPreferences.

例如:

public void checkFirstRun() {
    boolean isFirstRun = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getBoolean("isFirstRun", true);
    if (isFirstRun){
        // Place your dialog code here to display the dialog

        getSharedPreferences("PREFERENCE", MODE_PRIVATE)
          .edit()
          .putBoolean("isFirstRun", false)
          .apply();
    }
}

这篇关于Android的:首先运行弹出的对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆