Questions tagged «looper»


4
无法在ProgressDialog的AsyncTask内未调用Looper.prepare()的线程内创建处理程序
我不明白为什么会收到此错误。我正在使用AsyncTask在后台运行一些进程。 我有: protected void onPreExecute() { connectionProgressDialog = new ProgressDialog(SetPreference.this); connectionProgressDialog.setCancelable(true); connectionProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); connectionProgressDialog.setMessage("Connecting to site..."); connectionProgressDialog.show(); downloadSpinnerProgressDialog = new ProgressDialog(SetPreference.this); downloadSpinnerProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); downloadSpinnerProgressDialog.setMessage("Downloading wallpaper..."); } 当我doInBackground()根据情况进入时: [...] connectionProgressDialog.dismiss(); downloadSpinnerProgressDialog.show(); [...] 每当我尝试时downloadSpinnerProgressDialog.show(),都会收到错误消息。 有想法吗?

4
如何创建Looper线程,然后立即向其发送消息?
我有一个工作线程位于后台,用于处理消息。像这样: class Worker extends Thread { public volatile Handler handler; // actually private, of course public void run() { Looper.prepare(); mHandler = new Handler() { // the Handler hooks up to the current Thread public boolean handleMessage(Message msg) { // ... } }; Looper.loop(); } } 从主线程(UI线程,没关系),我想做这样的事情: Worker worker = …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.