我有一个服务与以下构造函数:
public ShimmerService(Context context, Handler handler) {
mHandler = handler;
}
我想实例化这个服务类.我有以下代码但是,我不知道在哪里通过参数:
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder binder) {
mShimmerService = ((ShimmerService.ShimmerConfigureBinder) binder)
.getService();
Toast.makeText(ConfigureShimmer.this,
"Shimmer service has succesfully started.",
Toast.LENGTH_SHORT).show();
}
public void onServiceDisconnected(ComponentName className) {
mShimmerService = null;
}
};
我有其他一切设置,包括绑定,开始等等.但我在上面的代码中得到错误:
04-03 19:06:10.285: E/AndroidRuntime(16837): java.lang.RuntimeException: Unable to instantiate service com.milanix.androidecg.services.ShimmerService: java.lang.InstantiationException: can't instantiate class com.milanix.androidecg.services.ShimmerService; no empty constructor
我该如何解决这个问题?我需要在哪里传递参数?以下代码可以工作,但它更像是使用服务类作为类,而不是服务:
mShimmerService = new ShimmerService(this, mHandler);