How would I force the current thread to wait until another has finished before continuing.
In my program the user selects a MODE from an AlertDialog, I want to halt executing of the program before continuing as the mode holds important configuration for the gameplay.
new AlertDialog.Builder(this)
.setItems(R.array.game_modes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
setMode(TRAINING_MODE);
case 1:
setMode(QUIZ_MODE);
default:
setMode(TRAINING_MODE);
break;
}
//continue loading the rest of onCreate();
contineOnCreate();
}
})
.create().show();
If this is impossible can anyone give a possible solution?
You don’t.
No, you don’t. You want to exit out of the main application thread (so the dialog appears), and then kick off gameplay after the user dismisses the dialog by one means or another.
No, it doesn’t. All UI is done on the main application thread, dialogs included.
Then don’t do any of that until after the user has dismissed the dialog by one means or another.
Another option: move your “dialog” UI options into its own activity, and have users pass through it en route to the game activity.