java - Android: ActivityCompat.requestPermissions requires activity and not context :/ -


i'm calling activitycompat.requestpermissions in order permissions under android m, however, requires activity in argument. fine, except want call singleton, , singleton can used activity in app.

activitycompat.requestpermissions(context, permissions_location, request_location); 

i want avoid holding reference activity within singleton that's surefire recipe memory leak, , i'd prefer singleton not hold activity @ because requires useless code in activities call (every single 1 of them going have include argument in getinstance() in order singleton hold activity - singleton needs activity somewhere).

now, can technically activity , set null straight after request permission, still leaves me tons of useless activity arguments in every single activity make call singleton. there more elegant solution problem i'm not seeing?

the documentation on requestpermissions says activity parameter target activity want show pop if haven't included permission in manifest , purpose method requires pass activity , not context, because upon finish request permissions task return result calling activity(that activity passed parameter method). if adamant implementing through singleton suggest create function accepts activity in parameter , callbacks need handle callbacks if permissions given or not


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -