i'm tryin' to display a msg every 1 min!! non stop! i found exemple that display the msg just one time after a fixed delay!! can you help how can set it?? or if using timer is better how it works i need an exemple!!
public class TimertestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Handler handler = new Handler();
handler.postDelayed(
new Runnable() {
public void run() {
afficher();
}
}, 1000L);
}
public void afficher()
{
Toast.makeText(getBaseContext(),
"test",
Toast.LENGTH_SHORT).show();
}
}
Thanks!
Try this code -
public class TimertestActivity extends Activity {
Handler handler = new Handler();
Runnable runnable = new Runnable() {
public void run() {
afficher();
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
runnable.run();
}
public void afficher()
{
Toast.makeText(getBaseContext(),
"test",
Toast.LENGTH_SHORT).show();
handler.postDelayed(runnable, 1000);
}
}
// Timer using Handler
private final int SPLASH_TIME = 3000;
// Handling splash timer.
private void startSplashTimer() {
new Handler().postDelayed(
new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashScreen.this,MainActivity.class));
}
}, SPLASH_TIME);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With