Created
April 30, 2013 13:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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