SupportLifecycleFragmentImpl автоматически добавляет фрагмент при включении местоположения с помощью диалога Google - PullRequest
1 голос
/ 29 января 2020

SupportLifecycleFragmentImpl автоматически добавляет фрагмент при включении местоположения с помощью диалогового окна Google.

При вызове местоположения и когда отображается диалоговое окно для включения местоположения, оно автоматически добавляет фрагмент. При вызове getFragmentManager (). GetFragments () он показывает новый фрагмент, добавленный автоматически с тегом SupportLifecycleFragmentImpl. который создает проблему в backstack.

enter image description here

этот тег добавить

enter image description here

java код

public void enableLoc() {

    activity.setFinishOnTouchOutside(true);

    final int REQUEST_LOCATION = 199;

    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                @Override
                public void onConnected(Bundle bundle) {
                    Log.e("location", "Connect");
                }

                @Override
                public void onConnectionSuspended(int i) {
                    Log.e("location", "fail");
                    //googleApiClient.connect();
                }
            })
            .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(ConnectionResult connectionResult) {
                    Log.d("location", "Location error " + connectionResult.getErrorCode());
                }
            }).build();
    googleApiClient.connect();

    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(30 * 1000);
    locationRequest.setFastestInterval(5 * 1000);
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(locationRequest);
    builder.setAlwaysShow(true);

    SettingsClient client = LocationServices.getSettingsClient(activity);
    Task<LocationSettingsResponse> task = client.checkLocationSettings(builder.build());
    task.addOnSuccessListener(activity, new OnSuccessListener<LocationSettingsResponse>() {
        @Override
        public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
            // All location settings are satisfied. The client can initialize
            // location requests here.
            // ...
            Log.d("location_enable", "enable");
        }
    });

    task.addOnFailureListener(activity, new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            if (e instanceof ResolvableApiException) {
                // Location settings are not satisfied, but this can be fixed
                // by showing the user a dialog.
                try {
                    // Show the dialog by calling startResolutionForResult(),
                    // and check the result in onActivityResult().
                    ResolvableApiException resolvable = (ResolvableApiException) e;
                    resolvable.startResolutionForResult(activity,
                            REQUEST_LOCATION);
                } catch (IntentSender.SendIntentException sendEx) {
                    // Ignore the error.
                }
            }
        }
    });

}
...