The title of the android project is changed every 5 seconds.

Source: Internet
Author: User
Package COM. example. titleclockproject; import Java. util. timer; import Java. util. timertask; import android. OS. bundle; import android. OS. handler; import android. OS. message; import android. app. activity; import android. view. menu; import android. view. menuitem; import android. support. v4.app. navutils; public class mainactivity extends activity {private int COUNT = 1; private handler = new handler () {public void handlemessage (Android. OS. message MSG) {Switch (MSG. what) {Case 1: updatetitle (); break; default: Break ;}};@override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main); // The first method (starting after 1 second, with an interval of 5 seconds) timer = new timer (); timer. scheduleatfixedrate (New timertask () {@ overridepublic void run () {message = new message (); message. what = 1; handler. sendmessage (Message) ;}}, 1000,5000); // method 2 // titlechange = new titlechange (); // thread = new thread (titlechange ); // thread. start () ;}@ override public Boolean oncreateoptionsmenu (menu) {getmenuinflater (). inflate (R. menu. activity_main, menu); Return true;} // class titlechange implements runnable {// @ override // public void run () {// while (true) {// message = new message (); // message. what = 1; // handler. sendmessage (Message); // try {// thread. sleep (5000); //} catch (interruptedexception e) {// E. printstacktrace (); //} private void updatetitle () {This. settitle ("Welcome to project" + Count ++ );}}

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.