Skip to content

Repository files navigation

RunThreadExample

Repeat Every 6 second, delay 1 second

Timertimer = newTimer();
timer.scheduleAtFixedRate(newTimerTask() {
@Overridepublicvoidrun() {
Toast.makeText(MainActivity.this, "Coba", Toast.LENGTH_SHORT).show();
}
}, 1000, 6000);

Run Thread UI

runOnUiThread (newThread(newRunnable() {
publicvoidrun() {
Toast.makeText(MainActivity.this, "Coba", Toast.LENGTH_SHORT).show();
}
}));

Run Thread No UI

Threadtimer = newThread(){
publicvoidrun(){
try{
sleep(1000);
} catch (Exceptione) {
e.printStackTrace();
} finally {
//Toast.makeText(MainActivity.this, "Coba", Toast.LENGTH_SHORT).show();Log.d(getClass().getSimpleName(), "onCreate: ");
}
}
};
timer.start();

Run Thread No UI Delay 4 second

newHandler().postDelayed(newRunnable() {
@Overridepublicvoidrun() {
//Toast.makeText(MainActivity.this, "Coba", Toast.LENGTH_SHORT).show();Log.d(getClass().getSimpleName(), "onCreate: ");
}
}, 4000);

Copyright 2021 M. Fadli Zein

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages