RxPermissions icon indicating copy to clipboard operation
RxPermissions copied to clipboard

repeated subscribe

Open codeCacher opened this issue 6 years ago • 6 comments

hello,I find a problem.When I requested permission for twice or more time, the accept call back may execute repeated.For example,when execute the code below:

    RxPermissions rxPermissions = new RxPermissions(MainActivity.this);
    rxPermissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
            .subscribe(new Consumer<Boolean>() {
                @Override
                public void accept(Boolean aBoolean) throws Exception {
                    Log.d(TAG, "first request");
                }
            });
    rxPermissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
            .subscribe(new Consumer<Boolean>() {
                @Override
                public void accept(Boolean aBoolean) throws Exception {
                    Log.d(TAG, "second request");
                }
            });

I thought the result should be like this: first request second request

but the result is: second request first request second request

The "second request" is printed twice.Then I read the code and find out the problem is caused by the "oneOf(trigger, pending(permissions))",it merge the original trigger and pending ,but when requesting the same permission, the pending will return a non-empty Observable.So I modified code like this:

private Observable<Permission> request(final Observable<?> trigger, final String... permissions) {
    if (permissions == null || permissions.length == 0) {
        throw new IllegalArgumentException("RxPermissions.request/requestEach requires at least one input permission");
    }
    return trigger//oneOf(trigger, pending(permissions))
            .flatMap(new Function<Object, Observable<Permission>>() {
                @Override
                public Observable<Permission> apply(Object o) throws Exception {
                    return requestImplementation(permissions);
                }
            });
}

and the result become right. So why use “oneOf”?What did it use for? Looking forward to your reply!!

codeCacher avatar Mar 23 '18 07:03 codeCacher

I find the same issue.

zeyios avatar Jun 29 '18 09:06 zeyios

@codeCacher @AsiamCn I couldn't reproduce this issue, I tried it out but I'm having the expected behavior

com.tbruyelle.rxpermissions.sample D/RxPermissionsSample: first request
    second request

could you please create a demo project where it's reproducible and share it here please?

EDIT: Nvm, I was able to reproduce, I'll fix this soon.

epool avatar Jun 29 '18 17:06 epool

I also encountered this problem, has the library been fixed?

oneLZH avatar Oct 17 '18 07:10 oneLZH

I encountered the same problem

54binge avatar Oct 21 '19 08:10 54binge

I also cannot understand what the "pending" method means. The result I got is : if request one permission, like camera

first request
second request
second request

if request two or more permissions, like location and camera

second request
first request
second request

PengleiYu avatar Nov 16 '19 13:11 PengleiYu

@codeCacher @AsiamCn I couldn't reproduce this issue, I tried it out but I'm having the expected behavior

com.tbruyelle.rxpermissions.sample D/RxPermissionsSample: first request
    second request

could you please create a demo project where it's reproducible and share it here please?

EDIT: Nvm, I was able to reproduce, I'll fix this soon.

can you explan what "pending" method means, please? I am very confused.

PengleiYu avatar Nov 16 '19 13:11 PengleiYu