multithreading - How to elegantly access Android Views from other thread? -


I am using Twitter4j in asynchronous mode when I get a response in the listener then I want to change some of my activity. But the result is CalledFromWrongThreadException .

I know that I have the runOnUiThread method, but in addition to inline runway sections for this, what is the most beautiful solution for this?

Part of my activity:

  TwitterListener listener = new TwitterAdapter () {@ Override user delays on public Zero (user user) {super.gotUserDetail (user); FillInUserProfileDetails (user);    

I do not think any more "elegant" solution than Is Activity.runOnUiThread (Runable) or View Post (Runnabal) . Perhaps you have already seen the discussion of threading in Android docs:

Edit:

As stated, the Android UI Toolkit ThreadSafe Therefore, all interactions with it should be on the same thread, i.e. the UI thread of the application; And if you are going to pass from one thread to another, then you will need a runnable object to work in order to work.

I know that anonymous internal classes can mess, but these are quite common idioms in Java, because it is the closest thing available in the language. So the best thing for you, IMO, suppress your teeth and use the Activity.runOnUiThread , and remind that the grandeur is at the eye of the programmer.


Comments