7

If there any support Library function that could make the setCountDown function of the chronometer support by APIs lower than 24?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

2 Answers2

1

You can try RXJava to simple handle threads, timers, and many other functionalities.

The documentation for the timer operator says this:

Create an Observable that emits a particular item after a given delay

Thus the behavior you are observing is expected- timer() emits just a single item after a delay.

The interval operator, on the other hand, will emit items spaced out with a given interval.

For example, this Observable will emit an item every second:

Observable.interval(1, TimeUnit.SECONDS);

And an complete example:

Observable.interval(1,TimeUnit.SECONDS, Schedulers.io())
        .take(300) // take 300 second
        .map(v -> 300 - v)
        .subscribe(
            onNext -> {
                //on every second pass trigger
            },
            onError -> {
                //do on error
            },
            () -> {
                //do on complete
            },
            onSubscribe -> {
                //do once on subscription
            });
FarshidABZ
  • 3,860
  • 4
  • 32
  • 63
0

According to Android Documentation , its not possible with below API level 24. Chronometer widget only use count up. If you need to do so go with CountDownTimer.

For Example:

final int oneSecond = 1000; // in milliSeconds i.e. 1 second
final int tenSeconds = 100000; // 100 seconds
CountDownTimer cTimer =  new CountDownTimer(100000, oneSecond) {

     public void onTick(long millisUntilFinished) {

             int totalTime = 60000; // in milliseconds i.e. 60 seconds
             String v = String.format("%02d", millisUntilFinished/totalTime);
             int va = (int)( (millisUntilFinished%totalTime)/oneSecond);
             textView.setText("remaining seconds: " +v+":"+String.format("%02d",va));
     }

     public void onFinish() {
         textView.setText("done!");
     }
  };
  cTimer.start();

EDIT:

If you want to go with GitHub Solution then have a look at this and this

Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60