希望只安装了应用程序后,一旦显示一个对话框对话框、应用程序、安装了

2023-09-06 19:13:26 作者:是梦别喊疼想赢别喊停i

我怎样才能让安装我的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();
    }
}
 
精彩推荐