bsp;int N = mCallbacks.beginBroadcast(); try { for (int i = 0; i < N; i++) { mCallbacks.getBroadcastItem(i).showResult(i); } } catch (RemoteException e) { Log.e(TAG, "", e); } mCallbacks.finishBroadcast(); } private Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { callBack(); super.handleMessage(msg); } };} 然后是activity: package com.zhang.test; 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.os.RemoteException;import android.util.Log; import com.zhang.test.service.ICallback;import com.zhang.test.service.IService;import com.zhang.test.service.MainService; public class MainActivity extends Activity { private static final String TAG = "MainActivity"; private IService mService; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent i = new Intent(this, MainService.class); bindService(i, mConnection, Context.BIND_AUTO_CREATE); } @Override protected void onDestroy() { if(mService!=null){ try { mService.unregisterCallback(mCallback); } catch (RemoteException e) { Log.e(TAG, "", e); } } //destroy的时候不要忘记unbindService unbindService(mConnection); super.onDestroy(); } /** * service的回调方法 */ private ICallback.Stub mCallback = new ICallback.Stub() {