Android:Activity之间跳转和参数传递
打开新的Activity并传递参数
MainActivity.java传递参数
public void OpenNew(View v){
//新建一个显式意图,第一个参数为当前Activity类对象,第二个参数为你要打开的Activity类
Intent intent =new Intent(MainActivity.this,MainActivity2.class);
//用Bundle携带数据
Bundle bundle=new Bundle();
//传递name参数为tinyphp
bundle.putString("name", "tinyphp");
intent.putExtras(bundle);
startActivity(intent);
}
MainActivity2.java接收参数
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newtest);
//新页面接收数据
Bundle bundle = this.getIntent().getExtras();
//接收name值
String name = bundle.getString("name");
Log.i("获取到的name值为",name);
}