开发学院手机开发Android 开发 创建android的Service 阅读

创建android的Service

 2010-08-22 04:46:00 来源:WEB开发网   
核心提示:import android.content.ServiceConnection;import android.os.IBinder;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;imp

import android.content.ServiceConnection;

import android.os.IBinder;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.os.Bundle;

public class chap06ex1 extends Activity {

/** Called when the activity is first created. */

//listener;

/*Button startbt=(Button)findViewById(R.id.start);

Button stopbt=(Button)findViewById(R.id.stop);

Button bindbt=(Button)findViewById(R.id.bind);

Button unbindbt=(Button)findViewById(R.id.unbind);*/

ServiceConnection connection;

OnClickListener listener;

//connection;

//findViewById(R.id.start).setOnClickListener(listener)

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

listener=new OnClickListener(){

public void onClick(View v){

Intent i=new Intent(chap06ex1.this,SampleService.class);

switch(v.getId()){

case R.id.start:

startService(i);

break;

case R.id.stop:

stopService(i);

break;

case R.id.bind:

bindService(i,connection,BIND_AUTO_CREATE);

break;

case R.id.unbind:

unbindService(connection);

break;

default:

break;

}

}

};

findViewById(R.id.start).setOnClickListener(listener);

findViewById(R.id.stop).setOnClickListener(listener);

findViewById(R.id.bind).setOnClickListener(listener);

findViewById(R.id.unbind).setOnClickListener(listener);

/*startbt.setOnClickListener(listener);

stopbt.setOnClickListener(listener);

Tags:创建 android Service

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接