Search code examples
androiddreamservice

RunOnUiThread in DreamService?


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?


Solution

  • 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);