方法一:直接利用Intent
传递代码示例:
Intent intent = new Intent();
intent.putExtra("name", "张三");
intent.putExtra("age", 25);
接收代码:
String name = intent.getStringExtra("name");
int age = intent.getIntExtra("age", 0);
方法二:利用Intent和Bundle
传递代码示例:
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("name", "张三");
bundle.putInt("age", 25);
intent.putExtras(bundle);
接收代码:
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String name = bundle.getString("name");
int age = bundle.getInt("age", 0);