- 29
- 0
- 约3.01万字
- 约 28页
- 2017-07-09 发布于河南
- 举报
SDK Service线程详解
SDK Service线程详解
作者:高焕堂
试 阅:
public TextView tv, tv2;
private IBinder ib = null;
private Handler h1, h2;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
btn = new Button(this);
btn.setId(101);
btn.setText(create threads);
btn.setBackgroundResource(R.drawable.heart);
btn.setOnClickListener(this);
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(120, 50);
param.topMargin = 10;
layout.addView(btn, param);
btn2 = new Button(this);
btn2.setId(102);
btn2.setText(exit);
btn2.setBackgroundResource(R.drawable.heart);
btn2.setOnClickListener(this);
layout.addView(btn2, param);
tv = new TextView(this);
tv.setTextColor(Color.WHITE);
tv.setText();
LinearLayout.LayoutParams param2 = new LinearLayout.LayoutParams(FP, WC);
param2.topMargin = 10;
layout.addView(tv, param2);
tv2 = new TextView(this);
tv2.setTextColor(Color.WHITE);
tv2.setText();
layout.addView(tv2, param2);
setContentView(layout);
//-----------------------------------------------------
Intent in = new Intent(com.misoo.kx02c.REMOTE_SERVICE);
in.putExtra(key, 0);
bindService(in, mConnection, Context.BIND_AUTO_CREATE);
}
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder ibinder) {
ib = ibinder;
}
public void onServiceDisconnected(ComponentName className) {}
};
public void onClick(View v) {
switch (v.getId()) {
case 101:
h1= new Handler(){
public void handleMessage(Message msg) {
tv.setText((String)msg.obj);
}};
Thread t1 = new Thread(new Task());
正 文:
??????????? 由进程(Process)的主线程(Main thread)执行SDK-Service(如下图的myService)对象。
?
?
??????????? Android底层Binder Systembinding-time会从该进程的Thread pool里启动一个线程来执行SDK-ServiceBinder接口对象(myBinder)。
??????????? 执myActivity对线myBinder对线会(
原创力文档

文档评论(0)