title: Overlap of time IntentService
body: <p>I have little problem with overlap of time in ProgressBar. I have list card. When click this item show activity with display detail Card show progress bar with counts down the time. When time is over, Counts again. When add next Card and click this card show time previous Card. I don't idea why new Card 
  has the same time as old Card. </p>
  
  <p>ProgressBarService.class</p>
  
  <pre><code>public class ProgressBarService extends IntentService {
  
      private int interval;
      public static final String KEY_EXTRA_PROGRESS = "progress";
  
      public ProgressBarService() {
          super(ProgressBarService.class.getSimpleName());
      }
  
      @Override
      protected void onHandleIntent(Intent intent) {
          Intent broadcastIntent = new Intent();
          broadcastIntent.setAction(ProgressBarService.KEY_EXTRA_PROGRESS);
  
          if (intent != null) {
              interval = intent.getIntExtra("interval", 0);
              for (int i = interval; i &gt;= 0; i--) {
                  broadcastIntent.putExtra("progress", i);
                  sendBroadcast(broadcastIntent);
                  SystemClock.sleep(1000);
  
              }
          }
      }
  }
  </code></pre>
  
  <p>CardDeatlisActitvty.class </p>
  
  <pre><code>public class CardDetailsActivity extends AppCompatActivity {
  
      private Intent service;
      private ResponseReceiver receiver = new ResponseReceiver();
      private ProgressBar progressBar;
      private TextView secondTimeTextView;
      private int interval;
  
      public class ResponseReceiver extends BroadcastReceiver {
          // on broadcast received
          @Override
          public void onReceive(Context context, Intent intent) {
              // Check action name.
              if (intent.getAction().equals(ProgressBarService.KEY_EXTRA_PROGRESS)) {
                  int value = intent.getIntExtra("progress", 0);
                  new ShowProgressBarTask().execute(value);
              }
          }
      }
  
      class ShowProgressBarTask extends AsyncTask&lt;Integer, Integer, Integer&gt; {
  
          @Override
          protected Integer doInBackground(Integer... args) {
  
              return args[0];
          }
  
          @Override
          protected void onPostExecute(Integer result) {
              super.onPostExecute(result);
  
              progressBar.setProgress(result);
              secondTimeTextView.setText(" " + result + " ");
  
              if (result == 0) {
                  service = new Intent(CardDetailsActivity.this, ProgressBarService.class);
                  service.putExtra("interval", interval);
                  startService(service);
              }
  
          }
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
                  WindowManager.LayoutParams.FLAG_SECURE);
          setContentView(R.layout.activity_card_details);
  
          Bundle extras = getIntent().getExtras();
          if (extras != null) {
              intervalTotpEncrypt = extras.getString("intervalTotp");
          }
  
          interval = Integer.parseInt(intervalTotpDecrypt);
  
          progressBar.setMax(interval);
          progressBar.setProgress(interval);
  
          service = new Intent(this, ProgressBarService.class);
          service.putExtra("interval", interval);
          startService(service);
      }
  
      @Override
      protected void onResume() {
          super.onResume();
          registerReceiver(receiver, new IntentFilter(
                  ProgressBarService.KEY_EXTRA_PROGRESS));
      }
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
          unregisterReceiver(receiver);
      }
  
  }
  </code></pre>