How to elegantly access Android Views from another theme?

I am using Twitter4j in asynchronous mode. When I get the answer in Listener, I want to be able to change some views in my work, but this leads to CalledFromWrongThreadException.

I know that I can use the method runOnUiThread, but what is the most elegant solution for, besides embedding Runnable Classes?

Part of my activity:

    TwitterListener listener = new TwitterAdapter() {

        @Override
        public void gotUserDetail(User user) {
            super.gotUserDetail(user);

            fillInUserProfileDetails(user); 
+3
source share
1 answer

I do not think there is a more "elegant" solution than Activity.runOnUiThread(Runnable)or View.post(Runnable). You've probably already seen the discussion of threads in Android docs:

EDIT: http://android-developers.blogspot.com/2009/05/painless-threading.html

, Android UI , , ; , Runnable .

, , Java, , , , , , , Activity.runOnUiThread(Runnable), , .

+3

Source: https://habr.com/ru/post/1755485/


All Articles