Android: First run popup dialog

前端 未结 6 2175
感情败类
感情败类 2020-12-04 11:50

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:

<
6条回答
  •  眼角桃花
    2020-12-04 12:16

    Use SharedPreferences to store the isFirstRun 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 isFirstRun flag in SharedPreferences.

    Example:

    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();
        }
    }
    

提交回复
热议问题