title: BroadcastService restart itself when app killed
body: <p>I am using <a href="https://stackoverflow.com/questions/32028134/how-to-keep-a-countdowntimer-running-even-if-the-app-is-closed">this</a> broadcast service with countdown timer. But when i kill the app, it is not ticking on same time(second), it is starts again.</p>
  
  <p>Here is my code.   </p>
  
  <p><strong>BroadcastService:</strong> </p>
  
  <pre><code>package com.example.emre.denemeprojesi;
  
  import android.app.Service;
  import android.content.Intent;
  import android.os.CountDownTimer;
  import android.os.IBinder;
  import android.util.Log;
  
  public class BroadcastService extends Service {
  
      private final static String TAG = "BroadcastService";
  
      public static final String COUNTDOWN_BR = "com.example.emre.denemeprojesi";
      Intent bi = new Intent(COUNTDOWN_BR);
  
      CountDownTimer cdt = null;
  
      @Override
      public void onCreate() {
          super.onCreate();
  
          Log.i(TAG, "Starting timer...");
          System.out.println("STARTING TIMER");
  
          cdt = new CountDownTimer(60000, 1000) {
              @Override
              public void onTick(long millisUntilFinished) {
  
                  Log.i(TAG, "Countdown seconds remaining: " + millisUntilFinished / 1000);
                  bi.putExtra("countdown", millisUntilFinished);
                  sendBroadcast(bi);
              }
  
              @Override
              public void onFinish() {
                  Log.i(TAG, "Timer finished");
                  System.out.println("TIMER CANCELLED");
              }
          };
  
          cdt.start();
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
  
  
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          return super.onStartCommand(intent, flags, startId);
      }
  
      @Override
      public IBinder onBind(Intent arg0) {
          return null;
      }
  }
  </code></pre>
  
  <p><strong>Main Activity:</strong> </p>
  
  <pre><code>package com.example.emre.denemeprojesi;
  
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.content.IntentFilter;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.widget.TextView;
  
  public class MainActivity extends AppCompatActivity {
  
      private String TAG  ="Countdown Servisi";
      private TextView lblResult ;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          lblResult = (TextView)findViewById(R.id.lbl_result);
  
          startService(new Intent(this, BroadcastService.class));
          Log.i(TAG, "Started service");
      }
  
      private BroadcastReceiver br = new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
              updateGUI(intent); // or whatever method used to update your GUI fields
          }
      };
  
      @Override
      public void onResume() {
          super.onResume();
          registerReceiver(br, new IntentFilter(BroadcastService.COUNTDOWN_BR));
          Log.i(TAG, "Registered broacast receiver");
      }
  
      @Override
      public void onPause() {
          super.onPause();
          unregisterReceiver(br);
         Log.i(TAG, "Unregistered broacast receiver");
      }
  
      @Override
      public void onStop() {
          try {
              unregisterReceiver(br);
          } catch (Exception e) {
              // Receiver was probably already stopped in onPause()
          }
          super.onStop();
      }
      @Override
      public void onDestroy() {
          super.onDestroy();
         // stopService(new Intent(this, BroadcastService.class));
          //Log.i(TAG, "Stopped service");
  
      }
  
      private void updateGUI(Intent intent) {
          if (intent.getExtras() != null) {
              long millisUntilFinished = intent.getLongExtra("countdown", 0);
              System.out.println(millisUntilFinished); //&lt;&lt;&lt;bu göstermiyor&lt;&lt;&lt;&lt;&lt;&lt;
              Log.i(TAG, "Countdown seconds remaining: " +  millisUntilFinished / 1000);
              //
          }
      }
  
  
  }
  </code></pre>