开发者

Waiting for DialogActivity to return before continuing executing of the main thread

开发者 https://www.devze.com 2022-12-31 01:14 出处:网络
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 co

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 Aler开发者_Go百科tDialog.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?


How would I force the current thread to wait until another has finished before continuing.

You don't.

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.

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.

because the Alert loads in it's own thread therefore allowing the main thread to continue loading as normal

No, it doesn't. All UI is done on the main application thread, dialogs included.

No because some of the onStart() code controls activity state when the Activity loses focus and needs to be re-configured when the activity re-gains focus.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消