1.使用putextra
Intent intent = new Intent();
intent.putExtra("test","asdf");
intent.setClass(MainActivity.this,Demo1Activity.class);
startActivity(intent);
第二个页面接收 :
String stringExtra = getIntent().getStringExtra("test");
注意:这种方式仅限于在同进程中传递值,传递对象:
2.使用bundle传值
这里我们看下bundle的源码 继承baseBundle
public final class Bundle extends BaseBundle implements Cloneable, Parcelable
public void putByte(@Nullable String key, byte value) {
super.putByte(key, value);
}
其中的put方法都是调用父亲的put的方法
查看父亲的方法 实质就是一个arraylist
void putShort(@Nullable String key, short value) {
unparcel();
mMap.put(key, value);
}
ArrayMap<String, Object> mMap = null;
传值接收:
Bundle bundle = new Bundle();
bundle.putString("test","asdf");
intent.putExtras(bundle);
Bundle bundle = getIntent().getExtras();
String test = (String) bundle.get("test");