当前位置: 代码迷 >> Android >> android兑现多线程
  详细解决方案

android兑现多线程

热度:57   发布时间:2016-05-01 18:42:02.0
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());	}}
?

?

?

  相关解决方案