我可以使用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);
}
Service int []数组可以通过两种方式设置:
1. mBoundService.setListeners = genArr(); //genArr() returns int[]
2. mBoundBinder.setListeners(genArr());
答案 0 :(得分:0)
Google android.developer版本在Service类中使用以下内容。这会将必要的nested Binder class
缩减为返回服务对象本身的一个方法,因此可以直接访问其方法。尼斯。
public class LocalBinder extends Binder {
LocalService getService() {
// Return this instance of LocalService so clients can call public methods
return LocalService.this;
}
}