title: Countdown Timer in Android out of sync?
body: <p>I am trying to make a countdown timer. I have came up with this code and initially I thought it worked. However when I run the app two things happen which I don't know how to fix...</p>
  
  <ol>
  <li>It is out of sync, although it is the system Time and Date it said there was only 60 days left not 61 when I know it is 61!!</li>
  <li>If I close the app and go back it resets the counters...</li>
  </ol>
  
  <p>Any help with this would be appreciated, its not for anything particular just a personal project.</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) 
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          final TextView dateBx = (TextView) findViewById(R.id.textView1);
          final TextView mTextField = (TextView) findViewById(R.id.mTextField);
          final TextView minBx = (TextView) findViewById(R.id.minBx);
          final TextView hourBx = (TextView) findViewById(R.id.hourBx);
  
          //set todays date
          DateFormat dateFormat1 = new SimpleDateFormat("dd/MM/yyyy");
          Calendar cal1 = Calendar.getInstance();
          //target date
          DateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy");
          Calendar cal2 = Calendar.getInstance();
          cal2.set(2012,11,25);
          //set maths
          long time1 = cal1.getTimeInMillis();
          long time2 = cal2.getTimeInMillis();
          //difference variable
          long diff = time2 - time1;
          //equations
          long diffSec = diff / 1000;
          long dMins = diff / (60 * 1000);
          long dHour = diff / (60 * 60 * 1000);
          long dDay = diff / (24 * 60 * 60 * 1000);
  
         new CountDownTimer(diff, 1000) 
         {
  
               public void onTick(long millisUntilFinished) 
               {
                   mTextField.setText("Seconds remaining: " + millisUntilFinished / 1000);
                   dateBx.setText("Days remaining: " + millisUntilFinished / (24 * 60 * 60 * 1000));
                   minBx.setText("Minutes remaining: " + millisUntilFinished / (60 * 1000));
                   hourBx.setText("hours remaining: " + millisUntilFinished / (60 * 60 * 1000));
               }
  
               public void onFinish() {
                   mTextField.setText("done!");
               }
            }.start();
  
  
  
  }
  </code></pre>
  
  <p>My code is a combination of some things that I learnt, in java and android, if you think of a better way of doing it all together then please let me know :)</p>
  
  <p>Thanks</p>