what is the integer that return by getInt(string key) in android.os.Bundle?

hamid_c picture hamid_c · Jul 3, 2015 · Viewed 7.5k times · Source

i read document about getInt() method :

public int getInt (String key)

Returns the value associated with the given key, or 0 if no mapping of the desired type exists for the given key.

Parameters:

key a string

return:

an int value

but i can't get it that what it exactly return.

the ID of key that is in R.java or no something else???

Answer

Patrick picture Patrick · Jul 3, 2015

It returns whatever you've put in that bundle with the same key.

Bundle bundle = new Bundle();
bundle.putInt("KEY", 1);
int value = bundle.getInt("KEY"); // returns 1

It's simply a map/dictionary datatype where you map a string value with something else. If you have other datatypes, you should use the appropriate put/get-methods for that datatype.