How to show toast in AsyncTask in doInBackground

后端 未结 9 770
灰色年华
灰色年华 2020-11-27 23:01

In one of my activities I\'m using AsyncTask. In doInBackground() I\'m making calls to various methods. In one of these methods I\'m getting an exc

9条回答
  •  不知归路
    2020-11-27 23:16

    Create a handler object and execute all your Toast messages using that.

    @Override
    protected Void doInBackground(Void... params) {
    
        Handler handler=new handler();
        handler=  new Handler(context.getMainLooper());
        handler.post( new Runnable(){
            public void run(){
                Toast.makeText(context, "Created a server socket",Toast.LENGTH_LONG).show(); 
            }
        });
      }
    

提交回复
热议问题