Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Activity re-created after denying permission #265

Closed
IsslamElkasah opened this issue Aug 12, 2020 · 3 comments
Closed

Activity re-created after denying permission #265

IsslamElkasah opened this issue Aug 12, 2020 · 3 comments

Comments

@IsslamElkasah
Copy link

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
Copy link
Contributor

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
Copy link
Author

IsslamElkasah commented Sep 3, 2020

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

@pedrovgs
Copy link
Contributor

pedrovgs commented Sep 4, 2020

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.

@pedrovgs pedrovgs closed this as completed Sep 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants