Android how to runOnUiThread in other class?

后端 未结 6 1938
再見小時候
再見小時候 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:19

    class MainActivity extends Activity implements Runnable{
    
        public void oncreate(){
            new Thread(this).start();
        }
    
        public void  run(){
            //here is code for download data from server after completion this and in handler  i m call other class in setdata() method....
        }
    
        public void setdata();
        {
            new checkData(this,MainActivity.this);
        }
    }
    
    class checkData{
    
        public void checkdata(Context context,MainActivity mainactivity){
           mainactivity.runUIonthread()..is works fine for me.....
        }   
    
    }
    

提交回复
热议问题