Android 实例展现如何不同程序间的Serivce调用
2010-09-15 00:10:00 来源:WEB开发网import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class ServiceActivity extends Activity {
private EditText ev1;
private EditText ev2;
private Button bstart;
private Button bstop;
private Button bget;
private Button bset;
private TextView tv;
private IDemoServiceBinder dsb;
private ServiceConnection sc = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.d("ServiceActivity", "onServiceConnected");
dsb = IDemoServiceBinder.Stub.asInterface(service);
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.d("ServiceActivity", "onServiceDisconnected");
dsb = null;
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ev1 = (EditText) findViewById(R.id.EditText01);
ev2 = (EditText) findViewById(R.id.EditText02);
bstart = (Button) findViewById(R.id.b_start);
bstop = (Button) findViewById(R.id.b_stop);
bstart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// Intent demoService = new Intent(ServiceActivity.this,
// DemoService.class);
Intent demoService2 = new Intent("com.shinestudio.demo.demoservice");
赞助商链接