Want to display a dialog only once after the app been installed

前端 未结 1 1177
独厮守ぢ
独厮守ぢ 2020-12-18 06:11

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

相关标签:
1条回答
  • 2020-12-18 06:49

    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.

    ex (in your launching 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();
        }
    }
    
    0 讨论(0)
提交回复
热议问题