android Can't create handler inside thread that has not called Looper.prepare()

在android 线程中出现该错误

解决办法:

Handler handler = new Handler(){

        @Override
        public void handleMessage(Message msg) {
            if(msg.what == 3){
                Toast.makeText(DownloadService.this, "这里设置弹出的信息", 2000).show();
            }
        }
       
    };

 

class MyThread implements Runnable{

@Override
        public void run() {

            Message msg = new Message();
            msg.what = 3;
            handler.sendMessage(msg);
        }
       
    }

你可能感兴趣的:(android Can't create handler inside thread that has not called Looper.prepare())