导航:首页 > 网络数据 > androidbundle传大数据

androidbundle传大数据

发布时间:2023-09-25 20:59:18

❶ android bundle 如何传递自定义对象数组

在Android开发中,有时候需要从一个Activity中传递数据到另一个Activity中,在Bundle中已经封装好了简单数据类型,例如String ,int ,float等。但是如果我们想要传递一个复杂的数据类型,比如一个Book对象,该怎么办呢看

细的看了一下Bundle中的方法,其中有一个是putSerializable()方法,Serializable对象是一个可恢复对象接口,我们只需
要让Book对象实现Serializable接口,就可以使用Bundle.putSerializable()方法传递Book对象了。废话不多说
了,现将代码贴上:
Book类:
package com.bundletest.model.fneg;
import java.io.Serializable;
/**
*@Copyright:Copyright (c) 2008 - 2100
*@Company:Sagret
*@Author:fengcunhan [email protected]
*@Package:com.bundletest.model.fneg
*@FileName:Book.java
*@Time:2010-12-19
*@User:feng
*/
public class Book implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String name;
private String id;
private String author;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
}
实例化Book类,得到Book对象book以及设置成员变量:
if(TextUtils.isEmpty(bookName)||TextUtils.isEmpty(author)||TextUtils.isEmpty(id)){
Toast.makeText(AndroidBundleActivity.this, "输入框不能为空", Toast.LENGTH_SHORT).show();
}else{
Book book=new Book();
book.setName(bookName);
book.setAuthor(author);
book.setId(id);
Intent intent=new Intent(AndroidBundleActivity.this,RecieveActivity.class);
Bundle bundle=new Bundle();
bundle.putSerializable("book", book);
intent.putExtras(bundle);
startActivity(intent);
}
在另一个Activity中获取传递过来的book对象,并显示:
Intent intent=this.getIntent();
Bundle bundle=intent.getExtras();
Book book=(Book)bundle.getSerializable("book");
nameText.setText("书名:"+book.getName());
authorText.setText("作者:"+book.getAuthor());
idText.setText("ID:"+book.getId());

❷ android intent跳转怎样传输大数据

在Activity或者组件之前传递信息时,一般采用intent绑定bundle的方式传值,但在使用过程中需要注意的是不要用bundle传递大容量数据:

在做项目的过程中,需要将听写界面的听写结果信息传递到听写记录界面供显示用,但是由于传递的数据量过大导致程序ANR,甚至直接报异常(传递的信息里面有bitmap转换成的byte数组、每一个词组的拼音、词语、语音信息),经过分析发现是由于bundle不能传递大容量的数据信息,在stackoverflow里面查阅发现有同行遇到类似的问题:

(1)“The size limit of Intent is still pretty low in Jelly Bean, which is somewhat lower than 1MB (around 90K), so you should always be cautious about your data length, even if your application targets only latest Android versions.”

(2)“As per my experience (sometime ago), you are able to put up to 1MB of data in a Bundleencapsulated inside Intent. I think, this restriction was valid up till Froyo or GingerBread.”

所以在通过bundle传递数据时只能传递较小的数据信息,对于在不同组件之间需要传递大容量数据的情况时,有几种替代方式可以解决不能用bundle传递这些数据的问题:

方法一:将需要传递的数据写在临时文件或者数据库中,再跳转到另外一个组件的时候再去读取这些数据信息,这种处理方式会由于读写文件较为耗时导致程序运行效率较低;

方法二:将需要传递的数据信息封装在一个静态的类中(注意当前组件和要跳转到的组件必须属于同一个进程,因为进程之间才能够共享数据),在当前组件中为类设置内容,然后再跳转到的组件中去取,这种处理方式效率很高,但是会破坏程序的独立性。

具体采用哪种替代方式取决于具体的情况,本人建议采取第二种处理方式,因为这样会大大提高程序的运行效率,至于程序的独立性,看你怎么去封装这个类了。

阅读全文

与androidbundle传大数据相关的资料

热点内容
编程模型怎么看图 浏览:177
相机7500打A档数据调多少 浏览:182
单引号双引号js 浏览:924
该文件包含违规内容是什么意思 浏览:926
maya脸部捕捉教程 浏览:762
联通app如何看宽带网速 浏览:605
maccs6打不开raw文件格式 浏览:730
UG90升级包360云盘 浏览:831
dnf念帝90版本宠物推荐 浏览:777
引用css文件到html网页里方法 浏览:217
天之眼导航地图怎么升级 浏览:934
word文件修改后怎么重新生成目录 浏览:973
win2008iis上传文件大小 浏览:948
js怎么取3cs的值 浏览:823
发文件到邮箱怎么发送失败是怎么回事 浏览:365
我和微信的故事盗号 浏览:836
网络审计设备品牌 浏览:335
app助手在哪里下载 浏览:822
qc导出excel错误无法导出至文件 浏览:95
微信下载的文件出现感叹号 浏览:706

友情链接