0

我无法在我的活动中绑定我的服务。你知道为什么吗?绑定服务返回假。我不知道为什么。甚至没有异常被抛出。

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 ); 
}

在 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。

4

0 回答 0