Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

putExtra() in android

Tags:

android

i want to know the usage of putExtra from very basic level

like image 349
prabhu Avatar asked Mar 07 '11 12:03

prabhu


2 Answers

If you want add information to your intent you can use this method. This information is represented as tuple (key, value). There are the number of value types that can be included into the extras of intent (for instance, int, int[], Bundle, Parcelable, and so on). For each this method there is a corresponding "read" method that is used to get the information from the intent.

So here is a possible example how to use this. Imagine that you want explicitly call the activity B from activity A and pass to it an array of integers:

int intArray[] = {1,2,3,4};
Intent in = new Intent(this, B.class);
in.putExtra("my_array", intArray);
startActivity(in);

To read the information in activity B (in onCreate() method) you should use the following code:

Bundle extras = getIntent().getExtras();
int[] arrayInB = extras.getIntArray("my_array");
like image 167
Yury Avatar answered Sep 23 '22 21:09

Yury


Add extended data to the intent.

The name must include a package prefix. For example, the app "com.android.contacts" would use names like "com.android.contacts.ShowAll".

Parameters:

name: The name of the extra data, with package prefix.

value: The double array data value.

Returns the same Intent object, for chaining multiple calls into a single statement.

like image 25
BadSkillz Avatar answered Sep 22 '22 21:09

BadSkillz