希望只安装了应用程序后,一旦显示一个对话框 [英] Want to display a dialog only once after the app been installed

查看:118
本文介绍了希望只安装了应用程序后,一旦显示一个对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能让安装我的Andr​​oid应用程序后,在设备上我的对话框出现一次?

How can I make my dialog appear only once after my Android app is installed on the device?

推荐答案

使用共享preference存储 firstrun 价值,并且在对您的发射活动查询值。如果该值被设置,则没有必要显示对话框。如果别的,显示对话框,并保存 firstrun 标志中共享preference。

Use SharedPreference to store the firstrun value, and check in your launching activity against that value. If the value is set, then no need to display the dialog. If else, display the dialog and save the firstrun flag in SharedPreference.

恩(你启动的活动):

public void onCreate(){
    boolean firstrun = getSharedPreference("PREFERENCE", MODE_PRIVATE).getBoolean("firstrun", true);
    if (firstrun){
        ...Display the dialog
        // Save the state
        getSharedPreference("PREFERENCE", MODE_PRIVATE)
            .edit()
            .putBoolean("firstrun", false)
            .commit();
    }
}

这篇关于希望只安装了应用程序后,一旦显示一个对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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