Android Wait for user input at AlertDialog to proceed

不羁岁月 提交于 2019-12-02 17:11:15

问题


I've see this subject been discussed here but can't seem to understand how to proceed.

In my onCreate I have code that checks if it is the first run of the application firstRun = getPref.getBoolean("firstRun", true);. If its the first time that the app is run, an alertdialog is shown with a message saying thats there is no database installed and the user as to press the OK button to download the database. If there are no errors than pref.putBoolean("firstRun", false); and the alertdialog it's not shown in the next runs.

Now I want to introduce a ChangeLog that it is only shown on the first run after the app is installed or upgraded. Since the changelog must come before the firstRun check, I should wait for the user press the changelog alertdialog OK button.

I've created the code for the changelog (it's working as expected) and after that code, I have the code of the firstRun. The problem is that the changelog is shown but than, if its in fact the first run of the app, the firstRun alertdialog is overlapping the changelog alertdialog.

So, here is my question.

What's the best wait to proceed so that the firstRun code is only executed after the user presses the OK button on the changelog alertdialog?


回答1:


What I understand is that the changeLog will run every first run of the app. So you can override onDismiss() of your changeLog AlertDialog. Then just put your code for firstRun check

@Override
public void onDismiss(DialogInterface dialog)
{
    // firstRun Check
    // call function to run AlertDialog code for first check if firstRun == true else close dialog
}



回答2:


Take another boolean variable isChengelog and set it false initialy, when user click on ChangeLog dialog set it true and save it in preferences. Further proceeding code check

if(isChengelog){
  //Show firstRun Aleret dialog
} 
else{
 //Not Show firstRun Aleret dialog
}



回答3:


Like Mukesh suggested but also put this in your callback for your changelog dialog.

// On "OK clicked"
public void onClick(DialogInterface dialog, int id){
    pref.putBoolean("changelog", false);
    showFirstRunDialog();
}

Define a convenience function to show the first run dialog:

public void showFirstRunDialog(){
    if(getPref.getBoolean("firstRun", true);) {
        //show dialog
    }
}

Make sure you include Mukesh's suggestion on start-up:

if(getPref.getBoolean("changelog", true);){
  //Show changelog dialog
} 
else{
   showFirstRunDialog();
}


来源:https://stackoverflow.com/questions/18830899/android-wait-for-user-input-at-alertdialog-to-proceed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!