WEB开发网
开发学院手机开发Android 开发 Android 实例展现如何不同程序间的Serivce调用 阅读

Android 实例展现如何不同程序间的Serivce调用

 2010-09-15 00:10:00 来源:WEB开发网   
核心提示:private Button b_get;private TextView tv;private IDemoServiceBinder dsb;private ServiceConnection sc = new ServiceConnection() {@Overridepublic void onServiceCo

private Button b_get;

private TextView tv;

private IDemoServiceBinder dsb;

private ServiceConnection sc = new ServiceConnection() {

@Override

public void onServiceConnected(ComponentName name, IBinder service) {

Log.d("ReadActivity", "onServiceConnected");

dsb = IDemoServiceBinder.Stub.asInterface(service);

}

@Override

public void onServiceDisconnected(ComponentName name) {

dsb = null;

}

};

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Intent s = new Intent("com.shinestudio.demo.demoservice");

this.bindService(s, sc, Context.BIND_AUTO_CREATE);

tv = (TextView) findViewById(R.id.TextView01);

b_get = (Button) findViewById(R.id.Button01);

b_get.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

if (dsb != null) {

try {

tv.setText(dsb.getPushString());

} catch (RemoteException e) {

e.printStackTrace();

}

}

}

});

}

@Override

protected void onPause() {

super.onPause();

this.unbindService(sc);

}

}

上一页  3 4 5 6 7 8 

Tags:Android 实例 展现

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