Without further discussion, today I recommend an Android multi-component synchronous timing open source tool class TimingX.

TimingX is a utility class for Android multi-component synchronization timing, implemented using Handler.

In projects we often have the need for timing, which can be expressed in a minute-second format starting from 00:00. TimingX is for timing, it does not currently support countdown, but it can be easily implemented if you have the need.

The project address

Gitee: Timingx, don’t be stingy with your Start! Also welcome to visit my personal blog, Thatcher Li, where you can share high-quality original technical articles.

Basic usage

  1. TimingX is very simple to use, the entire class source code is less than 200 lines, when a control to display timing, just need the following line of code to add to the timing control group
TimingX.builder().add(view);
Copy the code
  1. Start the time
TimingX.builder().start();
Copy the code

TimingX also supports chained calls if you don’t want to separate adding to the timing control group and starting the timing into two lines

TimingX.builder().add(view).start();
Copy the code

Note that once the start() method is called, all controls added to the control group are timed at the same time.

  1. Stop timing
TimingX.builder().stop();
Copy the code
  1. Destroy handlers to avoid memory leaks

When you don’t need timing, such as exiting an Activity or Fragment, remember to call it in their onDestroy() lifecycle method

TimingX.builder().destroy();
Copy the code

GetStatus () method

A publicly available method that gets the status of the current timer, start/pause. A lot of times you’ll use it to do your own business logic.

conclusion

If you have a better idea that the current features do not meet your business needs, please leave me a message. Or if you have a problem using it, you can issue it, and in the meantime, you can contribute source code for such extensions.