0

从 IntentService 中,如何进行异步调用并避免在回调到达之前关闭服务?

目前既没有 onConnected 也没有 onConnectionFailed 被调用:

private void initLocationUpdates() {

    Log.d(TAG, "initLocationUpdates");
    locationClient = new LocationClient(this, new ConnectionCallbacks() {

        @Override
        public void onDisconnected() {
            Log.d(TAG, "onDisconnected");
        }

        @Override
        public void onConnected(Bundle arg0) {
            Log.d(TAG, "onConnected");
            LocationRequest request = new LocationRequest();
            request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
            request.setInterval(5);
            locationClient.requestLocationUpdates(request, locationChangedPendingIntent);

        }
    }, new OnConnectionFailedListener() {

        @Override
        public void onConnectionFailed(ConnectionResult arg0) {
            Log.d(TAG, "onConnectionFailed");
        }
    });
}
4

1 回答 1

0

你没有打电话LocationClient.connect()

无论如何,您为什么要从 a 中调用它IntentService?它被设计为在后台工作,并在没有安排更多工作时被销毁。使用正常Service

于 2013-05-31T14:51:28.670 回答