Runnable is posted successfully but not run

后端 未结 6 1574
别跟我提以往
别跟我提以往 2020-12-08 07:45

In an existing Android project I\'ve encountered the following piece of code (where I inserted the debugging litter)

ImageView img = null;

public void onCre         


        
6条回答
  •  自闭症患者
    2020-12-08 08:05

    Use the following code, can post your code to MainThread anytime anywhere, but not depends any Context or Activity. That can prevent view.getHandler() failure or tedious onAttachedToWindow() stuffs etc.

        new Handler(Looper.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                //TODO
            }
        });
    

提交回复
热议问题