Android Service 笔记
2010-08-22 04:47:00 来源:WEB开发网package test.service;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class ServiceDemo extends Activity {
private static final String TAG = "ServiceDemo";
private Button mBtnStart, mBtnStop, mBtnBind, mBtnUnbind;
private MyTestService mService;
private boolean isBinded;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mBtnStart = (Button) findViewById(R.id.btnStartService);
mBtnStop = (Button) findViewById(R.id.btnStopService);
mBtnBind = (Button) findViewById(R.id.btnBindService);
mBtnUnbind = (Button) findViewById(R.id.btnUbindService);
mBtnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startService();
}
});
mBtnStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
stopService();
}
});
mBtnBind.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bindService();
}
});
mBtnUnbind.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
unbindService();
}
});
赞助商链接