Two writing methods and differences of Android new Handler

Writing one

Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            //todo 这里做一些事情。。。
        }
    };

This way of writing is actually not recommended, because the following method will be called first in the source code. If not, then this method will be called. This method is considered a spare tire method. In fact, the effect is the same. See your own habits.
Insert picture description here

Writing two

handler handler2 = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(@NonNull Message message) {
            return false;
        }
    });

Guess you like

Origin blog.csdn.net/yanwenyuan0304/article/details/105794732