java - Why does ActivityCompat.requestPermissions() only accept an integer request code between 0-255? -


i updated app targetsdkversion of 23, , implemented request various permissions. initial attempt using activitycompat.requestpermissions() caused illegalargumentexception thrown internals of fragmentactivity:

int request_code_a = 9001; activitycompat.requestpermissions(new string[ {manifest.permission.write_contacts}, request_code_a); // crashes 

java.lang.illegalargumentexception: can use lower 8 bits requestcode

however, if request code between 0-255, fine , permission request works expected.

int request_code_b = 101; activitycompat.requestpermissions(new string[ {manifest.permission.write_contacts}, request_code_b); // works correctly 

so question is, reasons there restricting possible values of integer in api this? same information supplied using byte, conscious decision has (apparently) been made use integer instead. case of allowing future extensibility?

quoting the source code fragmentactivity exception appears thrown:

    // use 8 bits of request code encode fragment id when     // requesting permissions fragment. hence, requestpermissions()     // should validate code against cannot override     // can not call super , activitycompat call     // override. handle use dependency inversion     // validator of request codes when requesting     // permissions in activitycompat. 

startactivityforresult() has 16-bit limit on request code, @ least in fragmentactivity.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -