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