looper

How to raise a toast in AsyncTask, I am prompted to used the Looper

删除回忆录丶 提交于 2019-11-27 01:41:54
I have tasks completed by AsyncTask in background. At some point I need to issue a Toast that something is completed. I've tried and I failed because Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() How can I do that? onPostExecute - executes on UI thread or publishProgress() ; in your doinbackground and protected void onProgressUpdate(Integer... progress) { } http://developer.android.com/reference/android/os/AsyncTask.html you can Toast inside doInBackground add this code where you want to Toast appear runOnUiThread(new Runnable()

What is the relationship between Looper, Handler and MessageQueue in Android?

筅森魡賤 提交于 2019-11-26 21:14:41
I have checked the official Android documentation/guide for Looper , Handler and MessageQueue . But I couldn't get it. I am new to android, and got very confused with these concepts. A Looper is a message handling loop: it reads and processes items from a MessageQueue . The Looper class is usually used in conjunction with a HandlerThread (a subclass of Thread ). A Handler is a utility class that facilitates interacting with a Looper —mainly by posting messages and Runnable objects to the thread's MessageQueue . When a Handler is created, it is bound to a specific Looper (and associated thread

深入理解Android消息机制

时光毁灭记忆、已成空白 提交于 2019-11-26 15:53:23
在日常的开发中,Android 的消息机制作为系统运行的根本机制之一,显得十分的重要。 从 Handler 发送消息开始 查看源码,Handler的post、send方法最终都会走到 代码 public final boolean sendMessageDelayed(Message msg, long delayMillis) { if (delayMillis < 0) { delayMillis = 0; } return sendMessageAtTime(msg, SystemClock.uptimeMillis() + delayMillis); } sendMessageDelayed 会走到 代码 private boolean enqueueMessage(MessageQueue queue, Message msg, long uptimeMillis) { msg.target = this; if (mAsynchronous) { msg.setAsynchronous(true); } return queue.enqueueMessage(msg, uptimeMillis); } 这里可以设置 Message 为异步消息 查看 queue 的 enqueueMessage 方法, 我们剥离出核心代码: 代码 if (p == null ||

AsyncTask and Looper.prepare() error

梦想与她 提交于 2019-11-26 13:04:30
I have the following code class OverlayTask extends AsyncTask<Void, Void, Void> { @Override public void onPreExecute() { if (sites != null) { myMapView.getOverlays().remove(sites); myMapView.invalidate(); sites = null; } } @Override public Void doInBackground(Void... unused) { grabShipsWithLocation(); return (null); } @Override public void onPostExecute(Void unused) { myMapView.getOverlays().add(sites); myMapView.invalidate(); isLoading = false; } } That seems to work fine on a few test devices but I am seeing a lot of errors appearing on the dev console. I can't seem to work out why and where

Can&#39;t create handler inside thread that has not called Looper.prepare() inside AsyncTask for ProgressDialog

泄露秘密 提交于 2019-11-26 12:58:41
I don't understand why I'm getting this error. I'm using AsyncTask to run some processes in the background. I have: 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);

How to raise a toast in AsyncTask, I am prompted to used the Looper

99封情书 提交于 2019-11-26 09:47:12
问题 I have tasks completed by AsyncTask in background. At some point I need to issue a Toast that something is completed. I\'ve tried and I failed because Caused by: java.lang.RuntimeException: Can\'t create handler inside thread that has not called Looper.prepare() How can I do that? 回答1: onPostExecute - executes on UI thread or publishProgress() ; in your doinbackground and protected void onProgressUpdate(Integer... progress) { } http://developer.android.com/reference/android/os/AsyncTask.html

What is the relationship between Looper, Handler and MessageQueue in Android?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 07:53:16
问题 I have checked the official Android documentation/guide for Looper , Handler and MessageQueue . But I couldn\'t get it. I am new to android, and got very confused with these concepts. 回答1: A Looper is a message handling loop: it reads and processes items from a MessageQueue. The Looper class is usually used in conjunction with a HandlerThread (a subclass of Thread ). A Handler is a utility class that facilitates interacting with a Looper —mainly by posting messages and Runnable objects to the

AsyncTask and Looper.prepare() error

你离开我真会死。 提交于 2019-11-26 03:10:56
问题 I have the following code class OverlayTask extends AsyncTask<Void, Void, Void> { @Override public void onPreExecute() { if (sites != null) { myMapView.getOverlays().remove(sites); myMapView.invalidate(); sites = null; } } @Override public Void doInBackground(Void... unused) { grabShipsWithLocation(); return (null); } @Override public void onPostExecute(Void unused) { myMapView.getOverlays().add(sites); myMapView.invalidate(); isLoading = false; } } That seems to work fine on a few test

Can&#39;t create handler inside thread that has not called Looper.prepare() inside AsyncTask for ProgressDialog

吃可爱长大的小学妹 提交于 2019-11-26 03:09:52
问题 I don\'t understand why I\'m getting this error. I\'m using AsyncTask to run some processes in the background. I have: 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