how to use runOnUiThread without getting “cannot make a static reference to the non static method” compiler error

后端 未结 4 572
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-13 15:53

I have a main class;

  ClientPlayer extends Activity {

and a service

  LotteryServer extends Service implements Runnable {
         


        
4条回答
  •  终归单人心
    2021-02-13 16:08

    Generally we use this method(RunOnUiThread) when we try to update our UI from a working thread. but As you are Using Service Here, runOnMainThread is seems inappropriate as per your situation.

    Better to Use Handler here. Handler is an element associated to the thread where is created, you can post a runnable with your code to the Handler and that runnable will be executed in the thread where the Handler was created.

    Create a Handler on your Service in his MainThread and post Runnables on it / send messages to it.

提交回复
热议问题