public void onServiceConnected(ComponentName name, IBinder service) {
Log.i( "Service connection established","");
// that's how we get the client side of the IPC connection
api = com.oreilly.android.otweet.TweetCollectorApi.Stub.asInterface(service);
try {
api.addListener(collectorListener);
/* Intent i = new Intent(StatusListActivity.this, StatusListActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);*/
} catch (RemoteException e) {
Log.e("", "Failed to add listener", e);
}
答案 0 :(得分:0)
要在申请停止时停止服务,我们需要在unbindService()
中致电onDestroy()
。
编辑:
在您的链接中有代码
@Override
protected void onDestroy() {
super.onDestroy();
try {
api.removeListener(collectorListener);
unbindService(serviceConnection);
} catch (Throwable t) {
// catch any issues, typical for destroy routines
// even if we failed to destroy something, we need to continue destroying
Log.w(TAG, "Failed to unbind from the service", t);
}
Log.i(TAG, "Activity destroyed");
}