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

后端 未结 4 573
佛祖请我去吃肉
佛祖请我去吃肉 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 15:59

    There is a very simple solution to the above problem just make a static reference of your Activity before your onCreat() method

    MainActivity mn;
    

    then initialize it in you onCreat() method like this

    mn=MainActivity.this;
    

    and after that you just have to use it to call your runOnUiThread

    mn.runOnUiThread(new Runnable() {
                        public void run() {
                            tv.setText(fns);///do what
                                        }
                                    });
    

    hope it work.

提交回复
热议问题