我无法在我的活动中绑定我的服务。你知道为什么吗? BindService返回false。 我不知道为什么。什么都没有例外。
public class GPSService extends Service {
private final IBinder _IBinder = new GPSBinder( );
public class GPSBinder extends Binder {
public GPSService getService( ) {
return GPSService.this;
}
}
@Override
public void onCreate( ) {
super.onCreate( );
}
@Override
public IBinder onBind(Intent intent) {
return _IBinder;
}
@Override
public boolean onUnbind( Intent intent ){
return super.onUnbind( intent );
}
private final IBinder _IBinder = new GPSBinder( );
public class GPSBinder extends Binder {
public GPSService getService( ) {
return GPSService.this;
}
}
@Override
public void onCreate( ) {
super.onCreate( );
}
@Override
public IBinder onBind(Intent intent) {
return _IBinder;
}
@Override
public boolean onUnbind( Intent intent ){
return super.onUnbind( intent );
}
在onStart中绑定:
servCon = new ServiceConnection( ){
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.d("GPS", "Serv conn");
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.d("GPS", "Serv disc");
}
};
boolean ret = bindService( new Intent( this, GPSService.class), servCon, Activity.BIND_AUTO_CREATE );
ret值等于false。