Simply say the timer in Java, the actual need, no detailed

Source: Internet
Author: User

Because the Android program has an upgrade push, and put the push prompt window in the Kaiping map that page, and kaiping map page four seconds, and then go to the main interface, no upgrade nothing, but if you click Cancel then the window disappears, do not click the words have been shown, although the program has no bug, But the log output will be error, and the robustness of the program is certainly not, and then would like to use the thread sleep, but not appropriate, Bo Master selected timer, three seconds user does not operate automatically disappear, open screen display is still unaffected, good, on the code:

public class Timertaskclass {        timer timer;        Long endTime = System.currenttimemillis () +;        Public timertaskclass (int seconds) {            timer = new timer ();            Timer.schedule (New Localtimertask (), 0, seconds *);        }        Class Localtimertask extends TimerTask {            Boolean flag = true;            public void Run () {while                (flag) {                    if (system.currenttimemillis () = = EndTime) {                        L.D ("----------- Now the time-------------", System.currenttimemillis () +" ");                        Message m = Message.obtain ();                        M.what = 3;                        Progresshandler.sendmessage (m);                        Timer.cancel ();                        Flag = FALSE;}}}}    
This is done by recording the time of the system by calculating the difference to calculate the time, and then sending a message, handing over the task of updating the UI to handler processing.

Simply say the timer in Java, the actual need, no detailed

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.