Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Intents - putExtra, what happens with multiple occurances?

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!

like image 557
Eric Avatar asked Apr 26 '11 07:04

Eric


People also ask

What is the putExtra () method used with intent for?

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.

What is the importance of the putExtra () method in android how it is different from setData ()?

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() .

What is the use of putExtra in Android?

PutExtra(String, Single)Add extended data to the intent.

How can I get intent data from another activity?

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.


1 Answers

It will overwrite it. The extra attributes are essentially a single-value hash: new values overwrite any existing values.

like image 163
Femi Avatar answered Sep 27 '22 17:09

Femi