我可以通过使用 binder 对象或使用服务类对象本身来设置变量 int[]。代码在public class MyActivity extends Activity.
哪一个是要走的路,两者都有效:
private BackgroundService.BackgroundBinder mBoundBinder; // to get methods of nested binder class inside BackgroundService
private BackgroundService mBoundService; //service class object
public void onServiceConnected(ComponentName className, IBinder binder) {
mBoundService = ((BackgroundService.BackgroundBinder) binder).getService(); //google version
mBoundBinder = ((BackgroundService.BackgroundBinder) binder);
}
服务 int[] 数组可以通过两种方式设置:
1. mBoundService.setListeners = genArr(); //genArr() returns int[]
2. mBoundBinder.setListeners(genArr());