1

I have a DreamService and I want to begin updating some UI stuff once a background thread completes (I'm raising an event to trigger this). In the main version of my app I just use RunOnUiThread to start the UI updates from the event but dreamService isn't descended from Activity so no such method. Weirdly, I'm not getting errors, I just get a blank screen. In my catlog I see warnings from my UI code but they are "empty" (no message, I just see "W at com.my.app" 3 times, different lines of code)

I think the most likely reason is triggering UI changes from an event raised in a thread so how can I do UI thread updates in a Dreamservice?

rene
  • 41,474
  • 78
  • 114
  • 152
James
  • 999
  • 2
  • 11
  • 22
  • create a handler from the ui thread (like in onCreate) and post on it. – njzk2 Dec 18 '12 at 10:09
  • OK, I tried adding a handler and sending the message from the event trigger- now in Catlog I get the warning about only the thread that created it can touch views, so I think you're along the right lines, I'll keep playing. – James Dec 18 '12 at 11:01

1 Answers1

2

Thanks to njzk2 for pointing me in the right direction. I found the answer here, specifically:

Handler handler = new Handler(Looper.getMainLooper());
handler.post(something_to_run_on_main_thread);
Community
  • 1
  • 1
James
  • 999
  • 2
  • 11
  • 22