I. Basic points of knowledge
1, Intent Intent = new Intent ();//Open browser's
Intent.setaction (Intent.action_view);
Intent.setdata (Uri.parse ("http://www.baidu.com"));
2, Systemclock.sleep (20000);//Sleep 20 seconds, used to disguise to win a
3, time-consuming operations should be done in sub-threads
Networked access to data
Copies of large files
All need to be placed on child threads to manipulate
The OnCreate () button clicks on the callback event, and the action shown is run inside the main thread. The UI thread.
4, the use of handler
New Handler ();
Message msg = new Message ();
Msg.what = update_display;//Unique identification of the set message
Msg.obj = i;
Mhandler.sendmessage (msg)
Second, the sample code
Package Com.example.handlertest;import Android.os.bundle;import Android.os.handler;import android.os.Message; Import Android.os.systemclock;import android.app.activity;import Android.view.menu;import Android.view.View;import Android.widget.textview;public class Mainactivity extends Activity {public TextView tv_num;public static final int UPDATE _number = 0;public int i = 0;public Handler Handler = new Handler () {public void Handlemessage (Android.os.Message msg) {if ( Msg.what = = update_number) {int i = (Integer) msg.obj;tv_num.settext (i + "");}};}; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.main); tv_num = (TextView) Findviewbyid (r.id.tv_number);} public void Add (view view) {new Thread () {@Overridepublic void run () {Super.run (), while (I <) {Systemclock.sleep ( ); i + = 1; Message msg = new Message (); msg.what = Update_number;msg.obj = I;handler.sendmessage (msg);}}}. Start ();} @Overridepublic Boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}
Third, the source code download
http://download.csdn.net/detail/caihongshijie6/7798627
Four