Skip to content

Instantly share code, notes, and snippets.

@daa233
Created February 13, 2016 10:01
Show Gist options
  • Select an option

  • Save daa233/d052fb95cf3dc9cd1bb4 to your computer and use it in GitHub Desktop.

Select an option

Save daa233/d052fb95cf3dc9cd1bb4 to your computer and use it in GitHub Desktop.
Android tip. Update UI everywhere.

How to update UI in some non-main threads?

Solution 1:

Use Handler and send Message.

Solution 2:

Force to run on UI thread.

new Thread() {
    public void run() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                // Update UI here
            }
        });
    }
}.start();
@daa233

daa233 commented Feb 13, 2016

Copy link
Copy Markdown
Author

When I used Handler, the Android Studio warned me that it might cause leak, so I chose to use solution 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment