0

I want to create recycle view with a counter in each row. Each row has a separate timer. This time should run separately. I able to create a timer but each time app gets restarted, the timer is getting reset.

Thank you in advance for your help!!

enter image description here

Rohit Deshmukh
  • 168
  • 1
  • 11
  • 1
    "each time app gets restarted"? What are you trying to do ? Do you want the time will also run when app is not open and resume with current updated value ? – ADM Feb 20 '18 at 05:27
  • https://stackoverflow.com/questions/32257586/how-to-handle-multiple-countdown-timers-in-recyclerview – duggu Feb 20 '18 at 05:30
  • check with -https://stackoverflow.com/questions/35860780/recyclerview-with-multiple-countdown-timers-causes-flickering – Adil Feb 20 '18 at 05:33
  • @ADM: Yes. I want to run counter even app is closed. It should resume to it's value when app is reopened. – Rohit Deshmukh Feb 20 '18 at 06:54
  • Run the counter on server and get the time at start of app . Thats the only solution i think . – ADM Feb 20 '18 at 07:00

1 Answers1

0

try this:

public CountDownTimer timer;

in onBindViewHolder(...)

 if (holder.timer != null) {
     holder.timer.cancel();
 }

 holder.timer = new CountDownTimer(timeEnd - System.currentTimeMillis(), 1000) {
     @Override
     public void onTick(long millisUntilFinished) {
       // update text..        
     }

     @Override
     public void onFinish() {
       // update text..
     }
    };

that worked for me!!!

izakos
  • 265
  • 2
  • 6