(Android Learning) Bundle

1. Bundle

Bundle is mainly used to transfer data; the data it saves exists in the form of key-value (key-value pairs).

Bundles are often used to transfer data between activities. The transferred data can be boolean, byte, int, long, float, double, string and other basic types or their corresponding arrays, or objects or object arrays. When the Bundle is passed an object or an object array, it must implement the Serializable or Parcelable interface.

2. Use (Android Activity data transfer: multiple transfers at a time)

The first Activity

 Intent itActivity = new Intent(MainActivity.this,SecondActivity.class);
 Bundle bd  = new Bundle();
 bd.putString("name","小明");
 bd.putInt("age",22);
 itActivity.putExtras(bd);
 startActivity(itActivity);

The second Activity

Intent itActivity2 = getIntent();
Bundle bd = itActivity2.getExtras();
String name = bd.getString("name");
int age = bd.getInt("age");
Log.d("intent","name:"+name+"  age:"+age);

Reference:
Detailed explanation of Android Bundle

Guess you like

Origin blog.csdn.net/weixin_45625639/article/details/123337075