Created
August 4, 2017 19:10
-
-
Save francisnnumbi/8802099de5f1b448d3ed570abbb1dbcf to your computer and use it in GitHub Desktop.
If you want a background task (thread) to update your ui, this is the snippet.
You need 3 things:
- a handler that enables repetition;
- the activity's method runOnUiThread() and;
- a runnable object in which run() method is implemented. All the ui updates are put inside run() method. And set the pause between repetitions with handler inside run…
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
| private void bgdrun() { | |
| final Handler handler = new Handler(); | |
| runOnUiThread(new Runnable(){ | |
| @Override | |
| public void run() { | |
| // update your views here. | |
| // do not use loops in here. | |
| handler.postDelayed(this, 1000); | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment