ANDROID Specifies the date time for the timer to perform the task

Source: Internet
Author: User

Place a timer with the specified detail date and time

1  Public classMainactivity extends Activity {2 3     PrivateHandler Handler =NewHandler () {4 @Override5          Public voidhandlemessage (Message msg) {6             Switch(msg.what) {7                  Case 1:8LOG.I ("====","performed a");9                     //the code that needs to be executed is put hereTen                      Break; One             } A         } -     }; -  the @Override -     protected voidonCreate (Bundle savedinstancestate) { - super.oncreate (savedinstancestate); - Setcontentview (r.layout.activity_main); +  -TimerTask task =NewTimerTask () { + @Override A              Public voidrun () { atHandler.sendemptymessage (1); -             } -         }; -Timer timer =NewTimer (true); -Timer.schedule (Task,strtodatelong ("2016-06-14 15:33:30")); -     } in  -  to     /** + * String type Time converted to date - * @param strdate the * @return *      */ $      Public StaticDate Strtodatelong (String strdate) {Panax NotoginsengSimpleDateFormat formatter =NewSimpleDateFormat ("YYYY-MM-DD HH:mm:ss"); -Parseposition pos =NewParseposition (0); theDate strtodate =formatter.parse (strdate, POS); +         returnstrtodate; A     } the}

ANDROID Specifies the date time for the timer to perform the task

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.