To put it simply, there is no detailed explanation of the timer in java.

Source: Internet
Author: User

To put it simply, there is no detailed explanation of the timer in java.

Because the Android program has an upgrade push, and the push Prompt window is placed on the page of the Open Graph, and the Open Graph page is four seconds, then the main interface is displayed, no upgrade is required, however, if you click Cancel, the window will disappear. If you do not click it, it will always be displayed. Although the program has no bugs, the log output will report an error, and the robustness of the program will certainly not work, the timer selected by the blogger disappears automatically when the user does not perform the operation for three seconds, and the screen opening display is still unaffected. Okay, go to the Code:

 

Public class TimerTaskClass {Timer timer; long endTime = System. currentTimeMillis () + 3000; public TimerTaskClass (int seconds) {timer = new Timer (); timer. schedule (new LocalTimerTask (), 0, seconds * 1000);} class LocalTimerTask extends TimerTask {boolean flag = true; public void run () {while (flag) {if (System. currentTimeMillis () = endTime) {L. d ("----------- current time -------------", System. currentTimeMillis () + ""); Message m = Message. obtain (); m. what = 3; progressHandler. sendMessage (m); timer. cancel (); flag = false ;}}}}}
Here, the system time is recorded and the difference is calculated to calculate the time, and then a message is sent to send the ui update task to handler for processing.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.