Let's say that I'm using an intent to get info back to the main class that called the current activity.
What would happen if say, I had two methods that might overlap the same field, like:
myIntent.putExtra("returnVal1",1000);
// many lines of code, later on...
myIntent.putExtra("returnVal1",5);
Would the "returnVal1" be updated to 5 in the intent, will it stay at 1000, or will this cause runtime crashes?
Thanks in advance, sent from mobile, not at a computer with eclipse atm or I would test myself!
Using putExtra() We can start adding data into the Intent object, we use the method defined in the Intent class putExtra() or putExtras() to store certain data as a key value pair or Bundle data object. These key-value pairs are known as Extras in the sense we are talking about Intents.
setData() is to pass data on which, action has to be taken; while putExtra() is to send extra information about the action. For example, if one is starting an activity to perform ACTION_CALL , then he has to set the number to call in setData() .
PutExtra(String, Single)Add extended data to the intent.
For this, Intent will start and the following methods will run: putExtra() method is used for sending the data, data in key-value pair key is variable name and value can be Int, String, Float, etc. getStringExtra() method is for getting the data(key) that is sent by the above method.
It will overwrite it. The extra attributes are essentially a single-value hash: new values overwrite any existing values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With