title: How to start timer for 3 hours even app is closed or back from activity in android
body: <p>once a timer start it couldn't be stop for 3 hours.if I click on backpress timer stoped.I am not sure how to pause and resume the timer as the textview.Please check my code.</p>
  
  <pre><code>TextView timer;
  
  SharedPreferences mpref;
  
  SharedPreferences.Editor ed;
  String output;
  MyCount counter;
  long seconds;
  
  long millisFinished;
  
  @Override
  
  protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.activity_start__test2);
      mpref=getSharedPreferences("com.example.bright", Context.MODE_PRIVATE);
  
        timer = (TextView) findViewById(R.id.timer);
  
  
  
      //startService(new Intent(this, MyService.class));
      counter = new MyCount(10800000, 1000);
  
      counter.start();
  
  
  }
  </code></pre>
  
  <p>countDownTimer method        </p>
  
  <pre><code>   public class MyCount extends CountDownTimer {
      Context mContext;
  
  
     public MyCount(long millisInFuture, long countDownInterval) {
          super(millisInFuture, countDownInterval);
          Log.e("timeeeee", millisInFuture + "");
      }
  
  
      public void onTick(long millisUntilFinished) {
          Log.e("time",millisUntilFinished+"");
  
          millisFinished = millisUntilFinished;
          timer.setText(formatTime(millisUntilFinished));
      /*    String timer_str = timer.getText().toString();
          //SharedPreferences sp=
  
          ed = mpref.edit();
          ed.putString("time", timer_str);
          ed.commit();*/
  
          if (seconds == 0) {
  
          }
      }
  
  
  
      public void onFinish() {
          Toast.makeText(getApplicationContext(), "Time Up", Toast.LENGTH_LONG).show();
      }
  
  
  }
  
  @Override
  protected void onResume() {
      super.onResume();
    /*//  Log.e("valueeeee",millisFinished+"");
     // new MyCount(millisFinished,1000);
     // Log.e("value",millisFinished+"");*/
    //counter
  
  }
  
  @Override
  public void onDestroy() {
      super.onDestroy();
      // counter.cancel();
  }
  
  //================================================================================Time format
  
  public String formatTime(long millis) {
      output = "";
      seconds = millis / 1000;
      long minutes = seconds / 60;
      long hours = minutes / 60;
  
      seconds = seconds % 60;
      minutes = minutes % 60;
      hours = hours % 60;
  
      String secondsD = String.valueOf(seconds);
      String minutesD = String.valueOf(minutes);
      String hoursD = String.valueOf(hours);
  
      if (seconds &lt; 10)
          secondsD = "0" + seconds;
      if (minutes &lt; 10)
          minutesD = "0" + minutes;
  
      if (hours &lt; 10)
          hoursD = "0" + hours;
  
      output = hoursD + " : " + minutesD + " : " + secondsD;
  
      return output;
  }
  </code></pre>
  
  <p>Please check my code</p>