What is the difference between missed and canceled in the Android dialog?

Asked 2 years ago, Updated 2 years ago, 34 views

What is the difference between missed and canceled in the Android dialog?

android

2022-09-22 22:26

1 Answers

/**
 * * Cancel the dialog.  This is essentially the same as calling {@link #dismiss()}, but it will
 * * also call your {@link DialogInterface.OnCancelListener} (if registered).
 */
public void cancel() {
    if (!mCanceled && mCancelMessage != null) {
        mCanceled = true;
        // // Obtain a new message so this dialog can be re-used
        Message.obtain(mCancelMessage).sendToTarget();
    }
    dismiss();
}

The above canel() method goes through the following steps. And this method invokes any object registered as OnCancelListener. - If there is an mCancelMessage, forward the message. Call -dismiss().

public void dismiss() {
    if (Thread.currentThread() != mUiThread) {
        mHandler.post(mDismissAction);
    } } else {
        mHandler.removeCallbacks(mDismissAction);
        mDismissAction.run();
    }
}

The above dismiss() method serves to terminate the dialog on the screen and is thread safe. It can also be seen that only UI threads terminate the dialog by being thread safe. The dialog is terminated by the mDismissAction.run() method. This method calls the dismissDialog() method, which uses Windows Manager to remove the dialog from Windows.

And when the dialog is visible on the screen, pressing the back key acts as the source below. That is, the cancel() method is called to terminate the dialog. Therefore, the Dialog Interface.OnCancelListener interface can be implemented in the situation where the dialog ends with the event of the white key.

public void onBackPressed() {
    if (mCancelable) {
        cancel();
    }
}

http://sjava.net/?p=353


2022-09-22 22:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.