Android :Timer issue - Android app unable to have consistent timer in

  • Thread starter Thread starter AC Question
  • Start date Start date
A

AC Question

We are developing a unique android java app which sends pictures to friends to solve a puzzle (just like Instagram) while using the app when there is an interruption for e.g., a call, or when device goes to sleep , a new timer starts running along with the old timer simultaneously. Can you guys suggest on how to resolve this bug ?
i.e.,
Seconds Remaining : 178 seconds
Seconds Remaining : 156 seconds
Seconds Remaining : 177 seconds
Seconds Remaining : 155 seconds
Seconds Remaining : 176 seconds
Seconds Remaining : 154 seconds
Seconds Remaining : 175 seconds
Seconds Remaining : 154 seconds

This is how the timer output is

Please find the relevant code below:
[sourcecode]
countDownTimer = new CountDownTimer(180000, 1000) {

public void onTick(long millisUntilFinished) {
// how.setText(millisUntilFinished / 1000 + "seconds remaining: " );
if(countTime.equals("yes"))
{
how.setText(count+" ");
//how.setText(millisUntilFinished / 1000 );
}
else
{
//how.setText(count+" Seconds");
how.setText(millisUntilFinished / 1000 + " seconds remaining" );
}
how.setTextSize(30);
count++;
if(count==180)
{
T.cancel();
T=null;


handler.postDelayed(new Runnable() {
@Override
public void run() {
MainActivity.this.finish();
}
}, 5000);

}
}

public void onFinish() {
how.setText("Time Is Up!");
}
}.start();
[/sourcecode]