Questions tagged [android-handler]

A Handler allows you to send and process `Message` and Runnable objects associated with a thread's `MessageQueue`. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue.

A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue.

848 questions
3
votes
3 answers

Avoid crashing the Handler thread in case of Runtime Exception?

I have a Handler(Thread) on which I post Runnables. In case a Runnable by mistake throws a RuntimeException, the whole app process crashes. As a default that sounds sensible, but I would like to catch such runtime exceptions, log an error, and…
TommyTh
  • 1,102
  • 9
  • 13
3
votes
3 answers

Handler postDelayed not able to update UI

Hello guys I'm trying to update the UI after a short delay and for this I'm using handler's postdelayed method. The following code initially sets my textview text to "Processing" and the code that's included in the the handler's runnable gets…
Adi
  • 197
  • 5
  • 16
3
votes
1 answer

Android Activity and Service communication: how to keep the UI up-to-date

I have an Activity A (not the main Activity) that launches a Service S that does some stuff in the background and, in the meanwhile, should made some changes to the UI of A. Let's just say that S count from 0 to 100 and A should display this count…
Paolo Rovelli
  • 9,396
  • 2
  • 58
  • 37
3
votes
1 answer

Handler.postDelayed(...) does not delay the Runnable

i've implemented an OnCompletionListener by myself which looks like this: public class SongEndCompletionListener implements OnCompletionListener{ String nextView; Context actualActivity; int stopTime; public…
Flo
  • 325
  • 2
  • 6
  • 18
3
votes
2 answers

Posting a runnable to a View that invalidates the View sometimes doesn't work

I been fighting an odd issue these last few days. I have a custom ExpandableListAdapter where each row contains an ImageView, among other things. I have a class that handles the asynchronous loading of images from the multitude of places they may…
dcow
  • 7,765
  • 3
  • 45
  • 65
3
votes
1 answer

How to test handler message using roboelectric or mockito

I'm trying to test a piece of code using roboelectric and mockito framework that contains a handler.sendMessage(msg): public void emailLogin(){ ... mHandler.sendMessage(message); } Handler mHandler = new Handler(new Callback() { public…
Mukesh Y
  • 762
  • 6
  • 16
3
votes
1 answer

asynctask not getting arraylist when called from a handler

I'm using a handler to start an asynctask but when doing so, my application crashes. The reason I am stuck is because if I start the asynctask via anything else (eg. onClickListener) then I can run it as many times, over and over again, and it works…
Badams
  • 569
  • 6
  • 25
3
votes
1 answer

How do I update a ProgressBar using a Handler?

I'm new to Android and I'm trying to work through a tutorial on using a ProgressBar in conjunction with a Handler. Just a note, I am targeting API 11. Here is my code with the errors I am getting inline: public class HandlerDemo extends Activity…
karan
  • 8,637
  • 3
  • 41
  • 78
3
votes
1 answer

For how long after finish() will Runnables posted to the Activity's Handler continue to execute?

I have a Handler which is linked to the UI thread. As expected, I can post() Runnables to it and have them execute on the UI thread. I also have a button, which when pressed will invoke finish() on the Activity. How does finish() affect a UI…
Dororo
  • 3,420
  • 2
  • 30
  • 46
3
votes
1 answer

Will this Handler still leak Context?

I know that if you initialize a Handler directly and use it in an Activity it will leak Context (courtesy of Alex Lockwood), for e.g. public class SampleActivity extends Activity { private final Handler mLeakyHandler = new Handler() { …
Arif Nadeem
  • 8,524
  • 7
  • 47
  • 78
3
votes
5 answers

Sending Message from Service to Activity

I have a Service and i try to send message to my primary Activity just like this: public void callAsynchronousTask() { final Handler handler = new Handler(); Timer timer = new Timer(); TimerTask doAsynchronousTask = new TimerTask() { …
Adam Varhegyi
  • 11,307
  • 33
  • 124
  • 222
3
votes
2 answers

Error java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0 in Android adapter

I have a adapter which extends BaseAdapter in my activity. In adapter I list the records. When the user click any record, options are listed. These options are "send" and "delete". Delete options remove record from list and send option send record…
3
votes
0 answers

Fixing SoundManager.release ANR from trace.txt

I am getting the following ANRs while calling SoundPool.release(). This is not a consistent defect, but happening randomly. Hence reproducing it is kinda time consuming. There are 2 ways to fix it, AsyncTask or Thread. I don't think I can use a…
Siddharth
  • 9,349
  • 16
  • 86
  • 148
3
votes
0 answers

Broadcasts vs Handlers for data transfer

First, I am new to Android and Java, but making steady progress. I have a question about the use of BroadCast Receivers Vs Handlers for data transfer for Andriod 3.0 + I currently have handlers embedded inside a run thread which receives data over a…
3
votes
1 answer

AsyncQueryHandler's call to onQueryComplete on ui thread? ( Android )

I am using AsyncQueryHandler and it calls onQueryComplete once the query is complete. My question: is onQueryComplete called on the UI thread? I know it does the query in the background. Does it matter where AsyncQueryHandler is instantiated? (If…