Android中Bundle的使用
来源:互联网 发布:黑暗的中世纪 知乎 编辑:程序博客网 时间:2024/05/29 07:09
Bundle类是一个key-value对,“A mapping from String values to various Parcelable types.”
类继承关系:
java.lang.Object
Android.os.Bundle
Bundle类是一个final类:
public final class
Bundle
extends Objectimplements Parcelable Cloneable
两个activity之间的通讯可以通过bundle类来实现,做法就是:
(1)新建一个bundle类
(2)bundle类中加入数据(key -value的形式,另一个activity里面取数据的时候,就要用到key,找出对应的value)(3)新建一个intent对象,并将该bundle加入这个intent对象两个类如下:intent从TestBundle类发起,到Target类。类1:TestBundle类:
类2: Target
- import android.app.Activity;
- import android.os.Bundle;
- public class Target extends Activity{
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.target);
- <span style="color:#ff6600;">
- Bundle bundle = getIntent().getExtras();
- </span> //得到传过来的bundle
- String data = bundle.getString("Data");//读出数据
- setTitle(data);
- }
- }
概况为以下几步:
1、实例化Bundle 一个对象,用putString(标记,数据)来将数据导入到Bundle对象中;
2、然后将Bundle对象导入到Intent对象中;
3、Intent启动另一个activity。
4、Bundle对象可以从activity.getIntent().getExtras()中返回。可见,启动当前activity
的Intent对象是由getIntent()来找到的。
5、通过Bundle的getString()方法,就可以读出所要的数据。
1 0
- Android中Bundle的使用
- android中bundle的使用
- Android中Bundle使用
- Android中Bundle使用
- Android中Bundle的使用示例
- android Bundle的使用
- Android中Bundle的用法
- Android Bundle的简单使用
- Android开发--bundle的使用
- Android -- Bundle对象的使用
- iOS中bundle的使用
- Android中使用Bundle交换数据
- Android中使用Bundle页面传值
- 7、Android中Bundle类的作用
- Android中Bundle类的作用
- Android中Bundle类的作用
- Android中Bundle类的作用
- Android中Bundle类的作用
- Advanced Installer 打包vs程序详解
- WebView支持上传
- 沉浸式状态栏解决方案(studio直接依赖一个库就可以)
- 数据结构实验之排序四:寻找大富翁
- <input type="submit" VS "button" ... />
- Android中Bundle的使用
- Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile)
- 2. 尚硅谷_佟刚_SpringMVC_HelloWorld
- 希望能记录每天成长的我
- C语言再学习 -- 运算符与表达式
- Message Flood(字典树)
- 一,数据库设计范式(MySQL为例)
- CURL是什么?
- 用SampleGrabber为实时采集视频叠加文字标识