title: creating second counter in android eclipse
body: <p>I'm making simple android app which should have counter which counts from 60 seconds down to 0 seconds. I have one idea how to do it, but I'm not sure if it is the smartest way to do it. And I'm not sure how to make it work in the code. </p>
  
  <p>Idea:
  In the .xml file I have added textView. I would make MyService class that extends Service which will be called by the .java file inside OnCreate function (because I want that counting starts immediately). MyService will change content of textView every second (I will have int counter which will be decreased every second and then text of textView will be changed). </p>
  
  <p>Is there any better way to do it?</p>
  
  <p>Here is MyService class:</p>
  
  <pre><code>  public class MyService extends Service {
  
          //for timer:
          int counter = 0;
  
          static final int UPDATE_INTERVAL = 1000;
          private Timer timer = new Timer();
  
          @Override
          public IBinder onBind(Intent arg0) {
              return null;
          }
  
  
          @Override
          public int onStartCommand(Intent intent, int flags, int startId) {
              doSomethingRepeatedly();
              return START_STICKY;
          }
  
  
          private void doSomethingRepeatedly() {
              timer.scheduleAtFixedRate( new TimerTask() {
                  public void run() {
  
                   //code for changing the content
  
                  }
              }, 0, UPDATE_INTERVAL);
          }
  
          @Override
          public void onDestroy() {
              super.onDestroy();
  
              //za timer
              if (timer != null){
                  timer.cancel();
  
              }
          }
      }
  </code></pre>
  
  <p>Do I have to put this code in separate .java file?</p>
  
  <p>I'm not sure how to write code for changing the content of textView, because I'm not sure if I can call id of textView because it is in the separated file?</p>
  
  <p>These would be functions for starting the Services:</p>
  
  <pre><code> public void startService(View view) {
          startService(new Intent(getBaseContext(), MyService.class));
   }
  
    public void stopService(View view) {
          stopService(new Intent(getBaseContext(), MyService.class));
      }
  </code></pre>
  
  <p>Where do I have to put them?</p>