Reputation: 23
I have problem with Countdown Timer. When I press button the Timer starts and after clossing app and waiting for a while the Timer stops. So the main idea what I want to do is to let app be awake in background process until the Timer Finish. I dont know the code or in which direction I should go. Please help me. Thanks a lot!
Upvotes: 2
Views: 84
Reputation: 596
//paste the following code inside your button method // mind you the example giving here is countdown for 60 seconds
int yoursecondsLeft = 0;
new CountDownTimer(60000, 100) { public void onTick(long milliseconds) {
/////////////////////////////////////////////////////////////
////////////////////////This is the code that convert to real system time so that yo will have your exact seconds//////////////////////////////
if (Math.round((float)milliseconds / 1000.0f) != yoursecondsLeft)
{
syoursecondsLeft = Math.round((float)milliseconds / 1000.0f);
}
//////////////////////////////////////////////////////////////////////////////
Log.i("test","ms="+milliseconds+" till finished="+yoursecondsLeft );
// You can print the count down value to your texview here: e.g tv.setText(yoursecondsLeft); }
public void onFinish() {
/*Close your application here: you can now call this method here: finish(); to end your application */
Log.i("finish","Countdown completed");
}
}.start();
Upvotes: 1