关于activity的直接传递数据【A向B传递数据】
来源:互联网 发布:淘宝销售宣传标语 编辑:程序博客网 时间:2024/06/05 06:28
1.传递简单类型的数据:
发送方A:
mIntent.putExtra("data", "hello nihao!!!");
接收方B:
mTextView.setText(mIntent.getStringExtra("data"));
PS:可以传递其他得数据类型如:float,int ,double等等;
2.传递数据包【两种方法】:
a.
发送方A:
mBundle= newBundle();
mBundle.putString("name","djw");
mBundle.putInt("age",25);
mIntent.putExtras(mBundle);startActivity(mIntent);
接收方B:
mIntent = getIntent();
mBundle = mIntent.getExtras();
mTextView.setText(String.format("name=%s,age=%d",mBundle.getString("name"),mBundle.getInt("age")));
b.
发送方A:
mBundle = new Bundle();
mBundle.putString("name","djw");
mBundle.putInt("age",25);
mIntent.putExtra("data",mBundle);
接收方B:startActivity(mIntent);
mIntent = getIntent();
mBundle = mIntent.getBundleExtra("data");
mTextView.setText(String.format("name=%s,age=%d",mBundle.getString("name"),mBundle.getInt("age")));
3.传递值对象:
发送方A:
mIntent = getIntent();
mIntent.putExtra("user", new User("duojiawen",2));startActivity(mIntent);
接收方B:
mIntent = getIntent();
mUser = (User) mIntent.getSerializableExtra("user");mTextView.setText(String.format("User info(name=%s,age=%d)",mUser.getName(),mUser.getAge()));
PS:User类一定实现Serializable对象;
4.接受B返回的结果:发送方A:
startActivityForResult(mIntent, 0);
0 0
- 关于activity的直接传递数据【A向B传递数据】
- Dialog向Activity传递数据
- Activity向服务传递数据
- fragment向activity传递数据
- Activity向Fragment传递数据
- Activity向Fragment传递数据
- Activity向Fragment传递数据
- 【intent extra】Android Activity直接传递数据
- Service实时向Activity传递数据案例
- Fragment向Activity中传递数据
- 5.27fragment向activity中传递数据
- Service实时向Activity传递数据案例
- Service实时向Activity传递数据案例
- fragment向activity传递数据-1
- fragment 如何向 activity 传递数据
- Activity如何向Fragment中传递数据
- 静态 注册的Broadcast Receiver怎么向Activity传递数据
- Android 向Activity传递数据的几种方法
- AFNetworking 3.0 源码解析之Reachability
- Xcode8上传应用包成功后,iTunes里不显示构建版本
- 移动端WebApp自适应实践
- 电路交换、报文交换和分组交换
- 将binaryproto文件转换为npy文件 代码
- 关于activity的直接传递数据【A向B传递数据】
- 【51Nod算法马拉松18 B】非010串
- 各种图片编码格式详解
- hihocode #1385 : A Simple Job
- 周末轻松一刻,欣赏完全由程序自己回忆的视频片段
- python学习之 requests库
- load-on-startup在web.xml中的含义
- 打造史上最简单的广告轮播图Banner
- 光束平差(Bundle Adjustment)算法