Android basics: running code in the UI thread

后端 未结 7 655
悲&欢浪女
悲&欢浪女 2020-11-22 11:55

In the viewpoint of running code in the UI thread, is there any difference between:

MainActivity.this.runOnUiThread(new Runnable() {
    public void run() {
         


        
7条回答
  •  广开言路
    2020-11-22 12:12

    I like the one from HPP comment, it can be used anywhere without any parameter:

    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            Log.d("UI thread", "I am the UI thread");
        }
    });
    

提交回复
热议问题