我有一个绑定到正在运行的服务的片段。所以要绑定我首先将ConnectionService字段声明为
private ServiceConnection mMyConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
MyService.MyBinder binder = (MyService.MyBinder) service;
mMyService = binder.getService();
mMyBound = true;
Log.d(TAG, "onServiceConnected");
…
}
@Override
public void onServiceDisconnected(ComponentName name) {
mMyBound = false;
}
};
然后在onCreate
里面我做
Intent intent = new Intent(getContext(), MyService.class);
getContext().bindService(intent, mMyConnection, Context.BIND_AUTO_CREATE);
我的Proguard-ed版本构建说连接为空并且在getContext().bindService(intent, mMyConnection, Context.BIND_AUTO_CREATE);
行崩溃。我正在使用
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
zipAlignEnabled true
}
}