怎么样把数据从一个activity(intent)发送到另一个呢?
Intent intent =new Intent(MainActivity.this,MainActivity2.class);
//用Bundle携带数据
Bundle bundle=new Bundle();
//传递name参数为tinyphp
bundle.putString("name", "tinyphp");
intent.putExtras(bundle);
startActivity(intent);
//新页面接收数据
Bundle bundle = this.getIntent().getExtras();
//接收name值
String name = bundle.getString("name");
这个用intent就可以实现了,intent可以像Map一样,以键值对的形式存储数据。Bundle也是可以存储数据,用Bundle存储数据的话,再将Bundle放入Intent里面,就可以了。
获取数据的话,在另一个activity里面调用getIntent方法,获取一个Intent对象,就可以从这个Intent对象里面获取数据 了。