bug: request permission twice, in one subscribe receive callback twice
Closed this issue · 0 comments
code
guess with this code , what will print?
RxPermissions(this).request(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE).subscribe()
RxPermissions(this).request(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE).subscribe { granted ->
Log.i(TAG(), "get permission")
}
we hope "get permission" will print once,but actually, it print twice
!!
analysis
I find code in RxPermissions#request(trigger, permissions)
, the oneOf
method return Observable.merge
if Observable.merge
contain two Observable
, the requestImplementation
method will execuate twice, finally the callback in subscribe will execuate twice!
so ,when the Observable.merge
contains two Observable
?
in most of time , pending
method will return Observable.empty()
, then wrapped by Observable.merge(trigger, Observable.empty())
, the result just contains one Observable
.But with the code above, the pedding
method will return Observable.just(TRIGGER)
, so the Observable.merge
contains two Observable
.
solution
I searched the history of those code, this related to #44 and #42 , but, when RxPermissionsFragment#onRequestPermissionsResult
callback, mSubjects
will remove all permissions
.
so , the pending
and oneOf
is out of date.
just delete those code.