GoogleApiClient尚未连接 - 导致崩溃

时间:2018-05-01 11:56:40

标签: android google-api-client

我已经读过这个问题的其他帖子,但是没有人帮我解决过。

我最终知道是什么导致了这个问题。一旦我启动该活动,应用程序就会崩溃。

是否应在之前的活动中初始化GoogleAPIClient?我正在通过一些自己的调整https://code.tutsplus.com/tutorials/how-to-work-with-geofences-on-android--cms-26639

来学习本教程

这是我的代码

package com.mad.losesano2;

import android.Manifest;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.location.Location;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.location.Geofence;
import com.google.android.gms.location.GeofencingRequest;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.Circle;
import com.google.android.gms.maps.model.CircleOptions;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

import java.util.ArrayList;


public class LoggedInActivity extends AppCompatActivity
        implements
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,
        OnMapReadyCallback,
        GoogleMap.OnMapClickListener,
        GoogleMap.OnMarkerClickListener,
        LocationListener, ResultCallback<Status> {

        private static GoogleApiClient googleApiClient;
        private Location lastLocation;
        private static final String TAG = MainActivity.class.getSimpleName();

        private ArrayList<Geofence> mGeofenceList = new ArrayList<>();
        ArrayList<Store> store_objects = new ArrayList<>();


        @Override
        protected void onCreate (Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_logged_in);


            createGoogleApi();
            store_objects = (ArrayList<Store>) getIntent().getSerializableExtra("stores_objects");

            for (Store store : store_objects) {
                Geofence geofence = new Geofence.Builder()
                        .setRequestId(Integer.toString(store.getStoreID()))

                        .setCircularRegion(
                                store.getLatitude(),
                                store.getLongitude(),
                                5
                        )
                        .setExpirationDuration(86400000)
                        .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
                        .build();


                mGeofenceList.add(geofence);
                GeofencingRequest request = new GeofencingRequest.Builder()
                        .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER)
                        .addGeofence(geofence)
                        .build();
                addGeofence(request);


            }

        }

    private void createGoogleApi() {
        Log.d(TAG, "createGoogleApi()");
        if ( googleApiClient == null ) {
            googleApiClient = new GoogleApiClient.Builder( this )
                    .addConnectionCallbacks( this )
                    .addOnConnectionFailedListener( this )
                    .addApi( LocationServices.API )
                    .build();
        }
    }

    private PendingIntent geoFencePendingIntent;
    private final int GEOFENCE_REQ_CODE = 0;
    private PendingIntent createGeofencePendingIntent() {
        Log.d(TAG, "createGeofencePendingIntent");
        if ( geoFencePendingIntent != null )
            return geoFencePendingIntent;

        Intent intent = new Intent( this, GeofenceTransitionService.class);
        return PendingIntent.getService(
                this, GEOFENCE_REQ_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT );
    }
    private void addGeofence(GeofencingRequest request) {
        Log.d(TAG, "addGeofence");
        if (checkPermission())
            LocationServices.GeofencingApi.addGeofences(
                    googleApiClient,
                    request,
                    createGeofencePendingIntent()
            ).setResultCallback(this);
    }

    protected void onStart() {
        super.onStart();
        googleApiClient.connect();
    }

    @Override
    public void onConnected(@Nullable Bundle bundle) {
        Log.i(TAG, "onConnected()");
        getLastKnownLocation();
    }
    @Override
    public void onConnectionSuspended(int i) {

    }
    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

    }
    @Override
    public void onMapClick(LatLng latLng) {

    }
    @Override
    public boolean onMarkerClick(Marker marker) {
        return false;
    }
    @Override
    public void onMapReady(GoogleMap googleMap) {

    }
    @Override
    public void onLocationChanged(Location location) {
    }
    private void getLastKnownLocation() {
        Log.d(TAG, "getLastKnownLocation()");
        if ( checkPermission() ) {
            lastLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
            if ( lastLocation != null ) {
                Log.i(TAG, "LasKnown location. " +
                        "Long: " + lastLocation.getLongitude() +
                        " | Lat: " + lastLocation.getLatitude());
                writeLastLocation();
                startLocationUpdates();
            } else {
                Log.w(TAG, "No location retrieved yet");
                startLocationUpdates();
            }
        }
        else {
            Log.d("LoSeSANO", "Permissions needed");
        }
    }
    private LocationRequest locationRequest;
    private final int UPDATE_INTERVAL =  1000;
    private final int FASTEST_INTERVAL = 900;
    private void startLocationUpdates(){
        Log.i(TAG, "startLocationUpdates()");
        locationRequest = LocationRequest.create()
                .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                .setInterval(UPDATE_INTERVAL)
                .setFastestInterval(FASTEST_INTERVAL);

        if ( checkPermission() )
            LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
    }
    private void writeActualLocation(Location location) {
    }
    private void writeLastLocation() {
        writeActualLocation(lastLocation);
    }
    private boolean checkPermission() {
        Log.d(TAG, "checkPermission()");
        // Ask for permission if it wasn't granted yet
        return (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
                == PackageManager.PERMISSION_GRANTED );
    }
    @Override
    public void onResult(@NonNull Status status) {

    }

    static Intent makeNotificationIntent(Context geofenceService, String msg)
    {
        Log.d(TAG,msg);
        return new Intent(geofenceService,MainActivity.class);
    }
}

堆栈跟踪

05-01 11:46:29.723 31239-31239/com.mad.losesano2 W/zygote: Skipping duplicate class check due to unrecognized classloader
05-01 11:46:29.737 31239-31239/com.mad.losesano2 W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
05-01 11:46:29.754 31239-31239/com.mad.losesano2 W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
05-01 11:46:29.756 31239-31239/com.mad.losesano2 I/BiChannelGoogleApi: [FirebaseAuth: ] No Fallback module; NOT setting up for lazy initialization
05-01 11:46:29.768 31239-31260/com.mad.losesano2 W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
05-01 11:46:29.798 31239-31260/com.mad.losesano2 I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions.
05-01 11:46:29.798 31239-31260/com.mad.losesano2 I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
05-01 11:46:29.817 31239-31239/com.mad.losesano2 D/FirebaseAuth: Notifying id token listeners about user ( EGM1SlMprNSWOQW4uei8bCkMEbm1 ).
05-01 11:46:29.841 31239-31239/com.mad.losesano2 D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
05-01 11:46:29.855 31239-31239/com.mad.losesano2 V/FA: Cancelling job. JobID: 578969223
05-01 11:46:29.870 31239-31239/com.mad.losesano2 V/FA: Registered activity lifecycle callback
05-01 11:46:29.871 31239-31239/com.mad.losesano2 I/FirebaseInitProvider: FirebaseApp initialization successful
05-01 11:46:29.922 31239-31239/com.mad.losesano2 V/FA: onActivityCreated
05-01 11:46:29.924 31239-31264/com.mad.losesano2 V/FA: Collection enabled
05-01 11:46:29.933 31239-31264/com.mad.losesano2 V/FA: App package, google app id: com.mad.losesano2, 1:271584553063:android:07e792f8b231f22b
05-01 11:46:29.934 31239-31264/com.mad.losesano2 I/FA: App measurement is starting up, version: 11910
05-01 11:46:29.934 31239-31264/com.mad.losesano2 I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
05-01 11:46:29.934 31239-31264/com.mad.losesano2 I/FA: To enable faster debug mode event logging run:
                                                         adb shell setprop debug.firebase.analytics.app com.mad.losesano2
05-01 11:46:29.934 31239-31264/com.mad.losesano2 D/FA: Debug-level message logging enabled
05-01 11:46:30.004 31239-31264/com.mad.losesano2 V/FA: Connecting to remote service
05-01 11:46:30.039 31239-31264/com.mad.losesano2 V/FA: Connection attempt already in progress
05-01 11:46:30.247 31239-31264/com.mad.losesano2 V/FA: Connection attempt already in progress
05-01 11:46:30.248 31239-31264/com.mad.losesano2 V/FA: Activity resumed, time: 35812609
05-01 11:46:30.254 31239-31264/com.mad.losesano2 I/FA: Tag Manager is not found and thus will not be used
05-01 11:46:30.256 31239-31264/com.mad.losesano2 D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-6487077170124859393}]
05-01 11:46:30.265 31239-31268/com.mad.losesano2 D/OpenGLRenderer: HWUI GL Pipeline
05-01 11:46:30.278 31239-31239/com.mad.losesano2 D/FirebaseApp: Notifying auth state listeners.
05-01 11:46:30.279 31239-31239/com.mad.losesano2 D/FirebaseApp: Notified 0 auth state listeners.
05-01 11:46:30.313 31239-31264/com.mad.losesano2 V/FA: Connection attempt already in progress

                                                       [ 05-01 11:46:30.352 31239:31268 D/         ]
                                                       HostConnection::get() New Host Connection established 0xa4f339c0, tid 31268
05-01 11:46:30.353 31239-31268/com.mad.losesano2 I/OpenGLRenderer: Initialized EGL, version 1.4
05-01 11:46:30.354 31239-31268/com.mad.losesano2 D/OpenGLRenderer: Swap behavior 1
05-01 11:46:30.354 31239-31268/com.mad.losesano2 W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
05-01 11:46:30.354 31239-31268/com.mad.losesano2 D/OpenGLRenderer: Swap behavior 0
05-01 11:46:30.370 31239-31268/com.mad.losesano2 D/EGL_emulation: eglCreateContext: 0xa7b05720: maj 3 min 0 rcv 3
05-01 11:46:30.434 31239-31268/com.mad.losesano2 D/EGL_emulation: eglMakeCurrent: 0xa7b05720: ver 3 0 (tinfo 0xa7b032a0)
05-01 11:46:30.435 31239-31268/com.mad.losesano2 E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
05-01 11:46:30.435 31239-31268/com.mad.losesano2 E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
05-01 11:46:30.436 31239-31268/com.mad.losesano2 E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
05-01 11:46:30.436 31239-31268/com.mad.losesano2 E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
05-01 11:46:30.575 31239-31268/com.mad.losesano2 D/EGL_emulation: eglMakeCurrent: 0xa7b05720: ver 3 0 (tinfo 0xa7b032a0)
05-01 11:46:31.050 31239-31264/com.mad.losesano2 D/FA: Connected to remote service
05-01 11:46:31.051 31239-31264/com.mad.losesano2 V/FA: Processing queued up service tasks: 4
05-01 11:46:31.101 31239-31239/com.mad.losesano2 W/View: dispatchProvideAutofillStructure(): not laid out, ignoring
05-01 11:46:31.135 31239-31239/com.mad.losesano2 I/AssistStructure: Flattened final assist data: 3576 bytes, containing 1 windows, 13 views
05-01 11:46:32.094 31239-31268/com.mad.losesano2 D/EGL_emulation: eglMakeCurrent: 0xa7b05720: ver 3 0 (tinfo 0xa7b032a0)
05-01 11:46:32.109 31239-31268/com.mad.losesano2 D/EGL_emulation: eglMakeCurrent: 0xa7b05720: ver 3 0 (tinfo 0xa7b032a0)
05-01 11:46:32.262 31239-31268/com.mad.losesano2 D/EGL_emulation: eglMakeCurrent: 0xa7b05720: ver 3 0 (tinfo 0xa7b032a0)
05-01 11:46:32.285 31239-31268/com.mad.losesano2 D/EGL_emulation: eglMakeCurrent: 0xa7b05720: ver 3 0 (tinfo 0xa7b032a0)
05-01 11:46:32.631 31239-31246/com.mad.losesano2 I/zygote: Do partial code cache collection, code=30KB, data=28KB
05-01 11:46:32.632 31239-31246/com.mad.losesano2 I/zygote: After code cache collection, code=29KB, data=28KB
05-01 11:46:32.632 31239-31246/com.mad.losesano2 I/zygote: Increasing code cache capacity to 128KB
05-01 11:46:33.288 31239-31239/com.mad.losesano2 E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
05-01 11:46:33.288 31239-31239/com.mad.losesano2 E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
05-01 11:46:33.329 31239-31246/com.mad.losesano2 I/zygote: Do partial code cache collection, code=58KB, data=55KB
05-01 11:46:33.329 31239-31246/com.mad.losesano2 I/zygote: After code cache collection, code=58KB, data=55KB
05-01 11:46:33.329 31239-31246/com.mad.losesano2 I/zygote: Increasing code cache capacity to 256KB
05-01 11:46:33.492 31239-31239/com.mad.losesano2 E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
05-01 11:46:33.492 31239-31239/com.mad.losesano2 E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
05-01 11:46:35.436 31239-31264/com.mad.losesano2 V/FA: Recording user engagement, ms: 5191
05-01 11:46:35.445 31239-31264/com.mad.losesano2 V/FA: Activity paused, time: 35817799
05-01 11:46:35.450 31239-31264/com.mad.losesano2 D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=5191, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-6487077170124859393}]
05-01 11:46:35.457 31239-31239/com.mad.losesano2 V/FA: onActivityCreated
05-01 11:46:35.572 31239-31264/com.mad.losesano2 V/FA: Activity resumed, time: 35817870
05-01 11:46:35.579 31239-31246/com.mad.losesano2 I/zygote: Do full code cache collection, code=111KB, data=120KB
05-01 11:46:35.580 31239-31246/com.mad.losesano2 I/zygote: After code cache collection, code=107KB, data=88KB
05-01 11:46:35.582 31239-31264/com.mad.losesano2 D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=MainActivity, firebase_previous_id(_pi)=-6487077170124859393, firebase_screen_class(_sc)=SignupActivity, firebase_screen_id(_si)=-6487077170124859392}]
05-01 11:46:35.632 31239-31268/com.mad.losesano2 D/EGL_emulation: eglMakeCurrent: 0xa7b05720: ver 3 0 (tinfo 0xa7b032a0)
05-01 11:46:35.730 31239-31239/com.mad.losesano2 W/View: dispatchProvideAutofillStructure(): not laid out, ignoring
05-01 11:46:35.740 31239-31239/com.mad.losesano2 I/AssistStructure: Flattened final assist data: 3344 bytes, containing 1 windows, 12 views
05-01 11:46:37.553 31239-31246/com.mad.losesano2 I/zygote: Do partial code cache collection, code=117KB, data=102KB
05-01 11:46:37.553 31239-31246/com.mad.losesano2 I/zygote: After code cache collection, code=117KB, data=102KB
05-01 11:46:37.553 31239-31246/com.mad.losesano2 I/zygote: Increasing code cache capacity to 512KB
05-01 11:46:40.256 31239-31246/com.mad.losesano2 I/zygote: Do full code cache collection, code=249KB, data=188KB
05-01 11:46:40.257 31239-31246/com.mad.losesano2 I/zygote: After code cache collection, code=244KB, data=159KB
05-01 11:46:40.668 31239-31264/com.mad.losesano2 V/FA: Inactivity, disconnecting from the service
05-01 11:46:41.894 31239-31268/com.mad.losesano2 D/EGL_emulation: eglMakeCurrent: 0xa7b05720: ver 3 0 (tinfo 0xa7b032a0)
05-01 11:46:41.913 31239-31268/com.mad.losesano2 D/EGL_emulation: eglMakeCurrent: 0xa7b05720: ver 3 0 (tinfo 0xa7b032a0)
05-01 11:46:41.987 31239-31246/com.mad.losesano2 I/zygote: Do partial code cache collection, code=246KB, data=171KB
05-01 11:46:41.987 31239-31246/com.mad.losesano2 I/zygote: After code cache collection, code=246KB, data=171KB
05-01 11:46:41.987 31239-31246/com.mad.losesano2 I/zygote: Increasing code cache capacity to 1024KB
05-01 11:46:42.109 31239-31268/com.mad.losesano2 D/EGL_emulation: eglMakeCurrent: 0xa7b05720: ver 3 0 (tinfo 0xa7b032a0)
05-01 11:46:42.134 31239-31268/com.mad.losesano2 D/EGL_emulation: eglMakeCurrent: 0xa7b05720: ver 3 0 (tinfo 0xa7b032a0)
05-01 11:46:42.410 31239-31268/com.mad.losesano2 D/EGL_emulation: eglMakeCurrent: 0xa7b05720: ver 3 0 (tinfo 0xa7b032a0)
05-01 11:46:42.428 31239-31268/com.mad.losesano2 D/EGL_emulation: eglMakeCurrent: 0xa7b05720: ver 3 0 (tinfo 0xa7b032a0)
05-01 11:46:47.845 31239-31239/com.mad.losesano2 D/LoSeSANO: Email Address: iuiu@ioi.com
05-01 11:46:47.855 31239-31239/com.mad.losesano2 W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms
05-01 11:46:48.729 31239-31253/com.mad.losesano2 D/FirebaseAuth: Notifying id token listeners about user ( 2Pdj86IuLWd7rFpxoYvJcQIShZT2 ).
05-01 11:46:48.729 31239-31239/com.mad.losesano2 D/FirebaseApp: Notifying auth state listeners.
05-01 11:46:48.729 31239-31239/com.mad.losesano2 D/FirebaseApp: Notified 0 auth state listeners.
05-01 11:46:48.730 31239-31253/com.mad.losesano2 D/FirebaseAuth: Notifying auth state listeners about user ( 2Pdj86IuLWd7rFpxoYvJcQIShZT2 ).
05-01 11:46:48.799 31239-31264/com.mad.losesano2 V/FA: Recording user engagement, ms: 13294
05-01 11:46:48.801 31239-31264/com.mad.losesano2 V/FA: Connecting to remote service
05-01 11:46:48.811 31239-31264/com.mad.losesano2 V/FA: Activity paused, time: 35831162
05-01 11:46:48.868 31239-31264/com.mad.losesano2 D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=13294, firebase_screen_class(_sc)=SignupActivity, firebase_screen_id(_si)=-6487077170124859392}]
05-01 11:46:48.868 31239-31239/com.mad.losesano2 V/FA: onActivityCreated
05-01 11:46:48.918 31239-31252/com.mad.losesano2 I/zygote: Background concurrent copying GC freed 14558(861KB) AllocSpace objects, 1(20KB) LOS objects, 52% free, 1362KB/2MB, paused 10.412ms total 87.383ms
05-01 11:46:49.066 31239-31264/com.mad.losesano2 V/FA: Connection attempt already in progress
05-01 11:46:49.075 31239-31264/com.mad.losesano2 V/FA: Connection attempt already in progress
05-01 11:46:49.076 31239-31264/com.mad.losesano2 V/FA: Activity resumed, time: 35831328
05-01 11:46:49.101 31239-31264/com.mad.losesano2 D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=SignupActivity, firebase_previous_id(_pi)=-6487077170124859392, firebase_screen_class(_sc)=StoreListRegisterActivity, firebase_screen_id(_si)=-6487077170124859391}]
05-01 11:46:49.163 31239-31264/com.mad.losesano2 V/FA: Connection attempt already in progress
05-01 11:46:49.373 31239-31264/com.mad.losesano2 D/FA: Connected to remote service
05-01 11:46:49.373 31239-31264/com.mad.losesano2 V/FA: Processing queued up service tasks: 4
05-01 11:46:49.382 31239-31268/com.mad.losesano2 D/EGL_emulation: eglMakeCurrent: 0xa7b05720: ver 3 0 (tinfo 0xa7b032a0)
05-01 11:46:52.349 31239-31264/com.mad.losesano2 V/FA: Recording user engagement, ms: 3383
05-01 11:46:52.350 31239-31264/com.mad.losesano2 V/FA: Activity paused, time: 35834711
05-01 11:46:52.355 31239-31264/com.mad.losesano2 D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=3383, firebase_screen_class(_sc)=StoreListRegisterActivity, firebase_screen_id(_si)=-6487077170124859391}]
05-01 11:46:52.357 31239-31239/com.mad.losesano2 V/FA: onActivityCreated
05-01 11:46:52.402 31239-31239/com.mad.losesano2 I/zzbz: Making Creator dynamically
05-01 11:46:52.416 31239-31239/com.mad.losesano2 I/DynamiteModule: Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:219
05-01 11:46:52.416 31239-31239/com.mad.losesano2 I/DynamiteModule: Selected remote version of com.google.android.gms.maps_dynamite, version >= 219
05-01 11:46:52.495 31239-31239/com.mad.losesano2 W/zygote: Skipping duplicate class check due to unrecognized classloader
05-01 11:46:52.556 31239-31239/com.mad.losesano2 I/Google Maps Android API: Google Play services client version: 11910000
05-01 11:46:52.567 31239-31239/com.mad.losesano2 I/Google Maps Android API: Google Play services package version: 12529024
05-01 11:46:52.943 31239-31239/com.mad.losesano2 D/MainActivity: createGoogleApi()
05-01 11:46:52.947 31239-31239/com.mad.losesano2 D/MainActivity: addGeofence
05-01 11:46:52.947 31239-31239/com.mad.losesano2 D/MainActivity: checkPermission()
05-01 11:46:52.948 31239-31239/com.mad.losesano2 D/MainActivity: createGeofencePendingIntent
05-01 11:46:52.953 31239-31239/com.mad.losesano2 D/AndroidRuntime: Shutting down VM
05-01 11:46:52.954 31239-31239/com.mad.losesano2 E/AndroidRuntime: FATAL EXCEPTION: main
                                                                   Process: com.mad.losesano2, PID: 31239
                                                                   java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mad.losesano2/com.mad.losesano2.LoggedInActivity}: java.lang.IllegalStateException: GoogleApiClient is not connected yet.
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                       at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                       at android.os.Looper.loop(Looper.java:164)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                    Caused by: java.lang.IllegalStateException: GoogleApiClient is not connected yet.
                                                                       at com.google.android.gms.common.api.internal.zzba.zze(Unknown Source:91)
                                                                       at com.google.android.gms.internal.zzceq.addGeofences(Unknown Source:5)
                                                                       at com.mad.losesano2.LoggedInActivity.addGeofence(LoggedInActivity.java:124)
                                                                       at com.mad.losesano2.LoggedInActivity.onCreate(LoggedInActivity.java:92)
                                                                       at android.app.Activity.performCreate(Activity.java:6975)
                                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
                                                                       at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
                                                                       at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                                       at android.os.Looper.loop(Looper.java:164) 
                                                                       at android.app.ActivityThread.main(ActivityThread.java:6541) 
                                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                                       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
05-01 11:46:52.976 31239-31246/com.mad.losesano2 I/zygote: JIT allocated 56KB for compiled code of void android.view.View.<init>(android.content.Context, android.util.AttributeSet, int, int)
05-01 11:46:52.999 31239-31246/com.mad.losesano2 I/zygote: Do full code cache collection, code=497KB, data=338KB
05-01 11:46:53.000 31239-31246/com.mad.losesano2 I/zygote: After code cache collection, code=497KB, data=286KB
05-01 11:46:54.966 31239-31470/com.mad.losesano2 W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.
05-01 11:46:54.974 31239-31470/com.mad.losesano2 I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4
05-01 11:46:54.974 31239-31470/com.mad.losesano2 I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 4
05-01 11:46:54.987 31239-31470/com.mad.losesano2 W/zygote: Skipping duplicate class check due to unrecognized classloader
05-01 11:51:47.993 31239-31260/com.mad.losesano2 I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions.
05-01 11:51:47.993 31239-31260/com.mad.losesano2 I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation

1 个答案:

答案 0 :(得分:0)

基于activity lifecycle说明,我会说您的代码会在onCreateaddGeofence过早地尝试访问googleApiClient实例,因为googlepiClient.connect()稍后会在onStart()中发生

相关问题