tbruyelle / RxPermissions

Android runtime permissions powered by RxJava2
Apache License 2.0
10.48k stars 1.31k forks source link

Permission dialog is stacking when "Don't keep activities" is on. #173

Open szymonkozak opened 7 years ago

szymonkozak commented 7 years ago

When I use request in onCreate, and I press home button when permission dialog is showing, after returning to the application there are 2 permissions dialogs stacked. This only happens when the "don't keep activities" option is enabled. Orientation change does not cause this problem.

tbruyelle commented 7 years ago

This may be a bug that occurs only on some manufacturer OS. Sorry I can't do anything for that.

meoyawn commented 6 years ago

this happens even on the standard Android emulator

mrArtCore commented 6 years ago

I think I got the problem, but don’t sure. You guys need to understand why it happens and modify your code. I suppose when activity created your permission dialog is showing, you press home, activity destroyed, but dialog not. When you open app again, activity creating againg, and you call reqestPermission again. If you changed implementation to standard android api, problem might be still present.

ashalmawia commented 6 years ago

This is not reproducible with the standard android api Activity, as Activity has a flag to check if there is a pending permission request From Activity.java API 26 requestPermissions():

Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions);
startActivityForResult(REQUEST_PERMISSIONS_WHO_PREFIX, intent, requestCode, null);
mHasCurrentPermissionsRequest = true;

It is reproducible, however, if you request permission with the framework Fragment API (instead of the Activity one). Which is what this lib does.

import android.app.Fragment;
RxPermissionsFragment extends Fragment

From Activity.java API 26 - surprise! no checks for the case with Fragment:

@Override
public void onRequestPermissionsFromFragment(Fragment fragment, String[] permissions,
                int requestCode) {
        String who = REQUEST_PERMISSIONS_WHO_PREFIX + fragment.mWho;
        Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions);
        startActivityForResult(who, intent, requestCode, null);
}

As a bottomline, the bug is kinda both in the lib and in the Android framework. RxPermissions is a pretty nice thing which I enjoy, but it always appears to be a bit undertested against "Do not keep activities" :)

By the way, the problem seems to be fixed for the support lib Fragment. Which might be an easy solution for the lib. The drawback is that it will require the calling activity to extend AppCompatActivity (which is, in my opinion, what it should be doing anyway - and this bug is a nice example of why...) Another solution might be just to add a flag before requesting permission, just like in the Activity class.