Skip to content

Instantly share code, notes, and snippets.

@pjdietz
Created April 30, 2013 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjdietz/5488864 to your computer and use it in GitHub Desktop.
Save pjdietz/5488864 to your computer and use it in GitHub Desktop.
Snippet to show how to wait, then execute code on the UI thread. The example shown is part of an Activity.
// Create a new thread inside your Actvity.
Thread thread = new Thread() {
@Override
public void run() {
// Block this thread for 2 seconds.
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
// After sleep finished blocking, create a Runnable to run on the UI Thread.
runOnUiThread(new Runnable() {
@Override
public void run() {
hideNavigation();
}
});
}
};
// Don't forget to start the thread.
thread.start();
// Borrowed from this Stack Overflow answer:
// http://stackoverflow.com/questions/3247554/how-to-show-a-view-for-3-seconds-and-then-hide-it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment