Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Android to design a countdown component

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Today, I will talk to you about how to use Android to design a countdown component. Many people may not know much about it. In order to let everyone know more, Xiaobian summarizes the following contents for everyone. I hope everyone can gain something according to this article.

1 Background

We often have countdown scenes in our projects, such as activity countdown, red envelope countdown, etc. Usually, we implement countdown schemes such as CountDownTimer in Android, Timer and ScheduleExcutorService in Java, and interval operator in RxJava. There are two typical problems in the actual project: one is that the implementation form of countdown is not uniform, and the reasons for the non-uniformity are divided into cognitive inconsistency, and each countdown scheme has its own advantages; the other is that there are a large number of countdown simultaneous execution.

2 Comparative analysis

The usage of several schemes is not the focus of this article. Here we list their characteristics in a table. The CountDownTimerManager at the bottom of the table is the freshly baked centralized countdown component that this article will introduce to you.

2.1 Is it a countdown?

The interval operator in Rx sends an event every once in a while. It can be said to be a counter, not a countdown. In actual projects, many students will find that it is used as a countdown. Below is an official RxJava illustration of interval:

interval.png *The Interval operator returns an Observable that emits an infinite sequence of ascending integers, with a constant interval of time of your choosing between emissions. (Simple understanding is to make a callback at fixed intervals)

Through the source code, we can also see that periodic scheduling is actually carried out in ObservableInterval.

public final class ObservableInterval extends Observable { @Override public void subscribeActual(Observer

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report