Skip to content

Instantly share code, notes, and snippets.

@francisnnumbi
Created August 4, 2017 19:10
Show Gist options
  • Save francisnnumbi/8802099de5f1b448d3ed570abbb1dbcf to your computer and use it in GitHub Desktop.
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…
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