Android 实战开发 页面跳转数据传递
2017-11-06 21:50
381 查看
Android 实战开发 页面间跳转已经实现过了,页面之间数据传递是怎么样的,做一个demo进行实现一、页面结构二 代码实现 1.第二页 按钮 回调
@Override
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(this,SecondActivity.class);
Bundle bundle = new Bundle();
bundle.putString("name","凌晨");
bundle.putInt("time",24);
intent.putExtras(bundle);
startActivityForResult(intent, 1001);
}2.第三页 接收上一页的数据传递
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_next_next);
closeBtn = (Button)findViewById(R.id.closeButton);
closeBtn.setOnClickListener(this);
TextView textView = findViewById(R.id.secondview);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String name = bundle.getString("name");
int age = bundle.getInt("time");
textView.setText(name +age+"点");
}3.第三页 按钮回调并封装数据
@Override
public void onClick(View v)
{
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("name","我返回了!");
intent.putExtras(bundle);
setResult(Activity.RESULT_OK,intent);
finish();
}4. 第二页接收第三页返回来的数据
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null) {
TextView textView = findViewById(R.id.tiptview);
Intent intent = getIntent();
String name = data.getStringExtra("name");
textView.setText(name);
}
}代码显示完毕。效果总结:在学习中
onActivityResult 一直不被调用,查其原因是因为 在父类的父类中 声明为保护类型 所以直接继承,既可以解决!
相关文章推荐
- Android开发:页面跳转和数据传递
- Android-应用开发-页面跳转和数据传递(六)
- Android应用开发:页面跳转和数据传递
- Android应用开发基础之六:页面跳转和数据传递
- Android(六)----页面跳转和数据传递
- Android Day06四大组件之Activity多页面跳转和数据传递
- Android页面跳转和数据传递
- Android初级教程理论知识(第五章页面跳转和数据传递)
- android 学习随笔十四(页面跳转与数据传递)
- android中页面跳转以及数据在Activity之间的传递
- Android页面跳转以及数据传递实现
- Android从一个APP跳转到另一个APP的主界面或某页面,并传递数据
- Android 开发实战 控件设置及页面跳转
- android开发基础:Intent与Bundle的使用,实现页面跳转及信息传递
- Android初级教程理论知识(第五章页面跳转和数据传递)
- Android视频学习(五):页面跳转和数据传递
- android 学习随笔十四(页面跳转与数据传递)
- Android基础笔记(七)-页面跳转和数据传递
- 初学移动开发技术_两个页面相互跳转,并且向上一个活动传递数据并显示
- Android 页面跳转和数据传递