putExtra() in android

你。 提交于 2019-11-25 15:17:49

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");
BadSkillz

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!