Android: regarding intentions, why setType () and setData () nullify each other?

I answered this question about why setType () and setData () do not work together. I still cannot find the reasons why. Logic eludes me.

From the documentation: Intent documentation

To set only the data URI, call setData (). To set only the MIME type, call setType (). If necessary, you can set both explicitly with setDataAndType ().

Note: if you want to set both the URI and the MIME type, do not call setData () and setType (), because each of them will invalidate the value of the other. Always use setDataAndType () to set the type of URI and MIME.

+4
source share
1

, , , - .

setType(), setData() setDataAndType() . , . , - . , , 16 , 8 , - 8 .

setType() :

field = (type & 0x0F) << 8;

, . , , .

setData ​​:

field = data & 0x0F;

, .

setDataAndType() - :

field = ((type & 0x0F) << 8) || (data & 0x0F);

, , .

, , :

  • . setType setData , , - ( ). - . , . , , , .
  • . setType() setData() , , , . , - setType(), setData(), URI , . , .
+2

All Articles