Karumi / Dexter

Android library that simplifies the process of requesting permissions at runtime.
http://karumi.com
Apache License 2.0
5.23k stars 671 forks source link

Activity re-created after denying permission #265

Closed IsslamElkasah closed 3 years ago

IsslamElkasah commented 3 years ago

Expected behaviour

Changing existing permission in app permissions settings from Allow to Deny then returning to the activity where settings was called should call onResume.

Actual behaviour

1- After clicking the back arrow from app settings and returning to my app, it gets recreated and Logcat shows onCreate being called not onResume. 2- When I click Go to Settings from my app and change a required permission from Deny to Allow, returning to app calls onResume. This should be the same as step 1 right?

Steps to reproduce

1- Grant one permission beforehand

2- Checking multiple permission in MainActivity inside onCreate

private void checkPermissions() {
    Dexter.withContext(getApplicationContext())
            .withPermissions(
                    Manifest.permission.ACCESS_FINE_LOCATION,
                    Manifest.permission.ACCESS_COARSE_LOCATION,
                    Manifest.permission.ACCESS_BACKGROUND_LOCATION,
                    Manifest.permission.SEND_SMS
            ).withListener(new MultiplePermissionsListener() {
        @Override public void onPermissionsChecked(MultiplePermissionsReport report) {
            if (report.areAllPermissionsGranted()) {

                Toast.makeText(getApplicationContext(), "All permissions are granted!", Toast.LENGTH_SHORT).show();
                //Continue using all app functionalities

            } else if (report.isAnyPermissionPermanentlyDenied()) {
               // navigating to Settings
                showSettingsDialog();

            } else {

                Toast.makeText(getApplicationContext(), "Permissions are not granted", Toast.LENGTH_SHORT).show();
                //Continue using limited app functionalities

            }
        }

        @Override public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
            token.continuePermissionRequest();
        }

    }).withErrorListener(new PermissionRequestErrorListener() {
        @Override
        public void onError(DexterError error) {
            Toast.makeText(getApplicationContext(), "Error occurred! ", Toast.LENGTH_SHORT).show();
            Log.e(TAG, "onError: " + error.toString() );
        }
    })
            .onSameThread()
            .check();
}

3- Deny granted permission and return using back arrows from app settings 4- Observe onCreate being called

Version of the library

6.2.1

pedrovgs commented 3 years ago

Hey @IsslamEl could you please create a repository reproducing this error? I tried to do it by myself, but I can't reproduce the error and I guess I'm missing any detail. You can fork Dexter example if you want 😃 Thank you in advance!

IsslamElkasah commented 3 years ago

Hi @pedrovgs I have created this repo with the described issue above. More details in the README file. Hope it helps

pedrovgs commented 3 years ago

Hi @IsslamEl I'm afraid there is no thing we can do to help you with this issue. I do not understand why, but whenever you remove some permissions already granted, the main activity is recreated. You can check how this is not related to Dexter if you modify your code to use the following onCreate implementation:


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

        Log.d(TAG, "onCreate");
        //checkPermissions();
        openSettings();
    }

If you do this, you'll see how after starting the app and denying the already granted permissions (you don't need Dexter to do this) the MainActivity is recreated. I'm so sorry, but I'm closing the issue now that we know there is nothing we can do to fix it in the library repository.

Thank you so much for creating the sample project.