WEB开发网
开发学院手机开发Android 开发 Android 开发教程之 Service 详解 阅读

Android 开发教程之 Service 详解

 2010-02-22 16:14:00 来源:WEB开发网   
核心提示:import android.widget.Toast;public class TestServiceHolder extends Activity {private boolean _isBound;private TestService _boundService;public void onCreate(Bun

import android.widget.Toast;

public class TestServiceHolder extends Activity {

private boolean _isBound;

private TestService _boundService;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.test_service_holder);

setTitle("Service Test");

initButtons;

}

private ServiceConnection _connection = new ServiceConnection {

public void onServiceConnected(ComponentName className, IBinder service) {

_boundService = ((TestService.LocalBinder)service).getService;

Toast.makeText(TestServiceHolder.this, "Service connected",

Toast.LENGTH_SHORT).show;

}

public void onServiceDisconnected(ComponentName className) {

// unexpectedly disconnected,we should never see this happen.

_boundService = null;

Toast.makeText(TestServiceHolder.this, "Service connected",

Toast.LENGTH_SHORT).show;

}

};

private void initButtons {

Button buttonStart = (Button) findViewById(R.id.start_service);

buttonStart.setOnClickListener(new OnClickListener {

public void onClick(View arg0) {

startService;

}

});

Button buttonStop = (Button) findViewById(R.id.stop_service);

buttonStop.setOnClickListener(new OnClickListener {

public void onClick(View arg0) {

stopService;

}

});

Button buttonBind = (Button) findViewById(R.id.bind_service);

buttonBind.setOnClickListener(new OnClickListener {

public void onClick(View arg0) {

bindService;

}

});

Button buttonUnbind = (Button) findViewById(R.id.unbind_service);

buttonUnbind.setOnClickListener(new OnClickListener {

上一页  2 3 4 5 6 7 8 9 10  下一页

Tags:Android 开发 教程

编辑录入:coldstar [复制链接] [打 印]
赞助商链接