Reputation: 1522
How can I run a Runable on the UI thread from a custom class? The method "runOnUiThread(Runnable)" would get the job done but it is a part of an Activity. I wonder if the Application class support something similar because its easy to get an instance of it. I have read about the annotation "@UiTread" from the androidannotation framework. Does this annotation also work for a custom class?
Upvotes: 1
Views: 725
Reputation: 8641
I suggest that you avoid running a Runnable on the UI thread. About the only reason I can think of to do it is to do some sort of timer that "sleeps" for an amount of time before it exits. In general, you can cause a lot of performance problems by using Threads, Runnables, and so forth outside of the Android framework. Not that they don't work, but then again you may tear your hair out trying to get them debugged.
Instead, to do "background" work, use an AsyncTask or an IntentService.
Upvotes: 1