How To Start An Activity Upon The Completion Of A Timer?
I'm trying to start a new activity 'SMS.java', if I dont respond to my timer within 30secs. After 30secs, the new ativity should be started. Can anyone help me out??? The class Tim
Solution 1:
For a timer method, better you can use with threading. It will work. This is the example for Show Timer in android using threads. It runs the thread every second. Change the time if you want.
TimerMyTimer=newTimer();
MyTimer.schedule(newTimerTask() {
@Overridepublicvoidrun() {
runOnUiThread(newRunnable() {
publicvoidrun() {
TimerBtn=(Button) findViewById(R.id.Timer);
TimerBtn.setText(newDate().toString());
}
});
}
}, 0, 1000);
Solution 2:
What I do is call a method from the Activity on my CountDownTimer class, like this:
//Timer Class inside my ActivitypublicclassSplashextendsCountDownTimer{
publicSplash(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@OverridepublicvoidonFinish() {
nextActivity(Login.class, true);
}
@OverridepublicvoidonTick(long millisUntilFinished) {}
}
//Method on my Activity ClassprotectedvoidnextActivity(Class<?> myClass, boolean finish) {
IntentmyIntent=newIntent(this, myClass);
myIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(myIntent);
if(finish)
finish();
}
Post a Comment for "How To Start An Activity Upon The Completion Of A Timer?"