Android how to runOnUiThread in other class?

后端 未结 6 1956
再見小時候
再見小時候 2020-11-28 08:22

In my application, in MainActivity, there is a thread which works fine. But when I call another class to get data from the server I can\'t run on a thread. See code exampl

6条回答
  •  伪装坚强ぢ
    2020-11-28 09:10

    Here's a solution if you don't want to pass the context:

    new Handler(Looper.getMainLooper()).post(new Runnable() {
        public void run() {
            // code goes here
        }
    });
    

提交回复
热议问题