android实现多线程
package cd.edu.app; import android.app.Activity; import android.os.Bundle; import android.os.HandlerThread; import android.os.Message; import cn.edu.subclass.MyHandler; public class AndroidThreadActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); HandlerThread handThread=new HandlerThread("app"); handThread.start(); MyHandler myHand=new MyHandler(handThread.getLooper()); Message msg=myHand.obtainMessage(); msg.sendToTarget(); System.out.println(Thread.currentThread().getName()); } }
package cn.edu.subclass; import android.os.*; public class MyHandler extends Handler{ public MyHandler(Looper loop){ super(loop); } public void handleMessage(Message message){ System.out.println(Thread.currentThread().getName()); } }
相关推荐
gavinvong 2019-07-01
安辉 2020-01-01
fengyeezju 2019-12-01
大黑 2019-06-21
tihi 2012-04-03
SouthWind0 2011-12-04
ALDRIDGE 2011-07-29
yeaperyeo 2011-03-14
稀土 2017-12-18
稀土 2017-12-14