intent传值传对象跳转
intent传值传对象跳转
1.传值
//原activity中存入一个字段
intent = new Intent(From.this, To.class);
intent.putExtra("switch", "chongzhi");
startActivity(intent);
//跳转至新的activity中后q取出该字段
Intent switchIntent = getIntent();
String myswitch = switchIntent.getStringExtra("switch");
2.传对象
intent = dialogInfo.getIntent();
/往Intent对象中传入一个对象
UserInfo 需实现Parcelable接口 创建creator
//存到一个Bundle 中
Bundle myBundle = new Bundle();
myBundle.putParcelable("userInfo", userInfo);
intent.putExtras(myBundle);
//在新的 Toactivity中取对象
Intent getIntent = getIntent();
UserInfo userInfo=(UserInfo)(getIntent.getParcelableExtra("userInfo"));
详情见http://caiwb1990.iteye.com/blog/1404201
3.附实现Parcelable的接口类 也就是序列化该对象
package com.example.entity;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
public class UserInfo implements Parcelable{
private int id;
private String username;
private String password;
private String phoneNum;
private double money;
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int arg1) {
// TODO Auto-generated method stub
dest.writeString(username);
dest.writeString(password);
dest.writeString(phoneNum);
dest.writeDouble(money);
}
public static final Creator<UserInfo> CREATOR = new Creator<UserInfo>() {
@Override
public UserInfo createFromParcel(Parcel source) {
UserInfo entity = new UserInfo();
// 顺序需和写入顺序一样
entity.username= source.readString();
entity.password = source.readString();
entity.phoneNum = source.readString();
entity.money = source.readDouble();
return entity ;
}
@Override
public UserInfo[] newArray(int arg0) {
// TODO Auto-generated method stub
return null;
}
};
}
intent传值传对象跳转的更多相关文章
- uniapp uni.navigateTo 传值传对象
uni.navigateTo({ url: '/pages/details?obj='+ encodeURIComponent(JSON.stringify(item)) }); 接收: onLoad ...
- intent传对象
intent还有一个很好用的地方,就是传输对象,但要注意的是这里的传输只是将对象复制了一份通过intent进行传递,并不能达到实时更新的效果,也就是这个对象等偏重于“读”.intent对这个对象有着严 ...
- Android 通过 Intent 传递类对象或list对象
(转:http://www.cnblogs.com/shaocm/archive/2013/01/08/2851248.html) Android中Intent传递类对象提供了两种方式一种是 通过实现 ...
- Intent之前的对象传递与fragment传递数据
Android中Intent传递类对象提供了两种方式一种是 通过实现Serializable接口传递对象,一种是通过实现Parcelable接口传递对象. 要求被传递的对象必须实现上述2种接口中的一种 ...
- Android 通过 Intent 传递类对象
Android中Intent传递类对象提供了两种方式一种是 通过实现Serializable接口传递对象,一种是通过实现Parcelable接口传递对象. 要求被传递的对象必须实现上述2种接口中的一种 ...
- Android 开发笔记——通过 Intent 传递类对象
Android中Intent传递类对象提供了两种方式一种是 通过实现Serializable接口传递对象,一种是通过实现Parcelable接口传递对象. 要求被传递的对象必须实现上述2种接口中的一种 ...
- android通过 Intent 传递类对象
Android中Intent传递类对象提供了两种方式一种是 通过实现Serializable接口传递对象,一种是通过实现Parcelable接口传递对象. 要求被传递的对象必须实现上述2种接口中的一种 ...
- android中用Intent传数据,如果用传递的是一个类,就将类实现Parcelable接口
Parcelable,内存单位,跨进程使用,或者intent传递对象的时候使用.android中用Intent传数据,如果用传递的是一个对象,就将对象实现Parcelable接口,而不是将对象序列化. ...
- intent 传参数
一.传递List<String>和List<Integer>以下以传递List<String>为例,发送List<String>语法为:intent.p ...
随机推荐
- linux编程学习
linux编程学习 工具篇 “公欲善其事,必先利其器”.编程是一门实践性很强的工作,在你以后的学习或工作中,你将常常会与以下工具打交道, 下面列出学习 C 语言编程常常用到的软件和工具. (一)操作系 ...
- 【bzoj2400】Spoj 839 Optimal Marks 按位最大流
Spoj 839 Optimal Marks Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 908 Solved: 347[Submit][Stat ...
- pat 团体天梯赛 L1-039. 古风排版
L1-039. 古风排版 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 中国的古人写文字,是从右向左竖向排版的.本题就请你编写 ...
- [LeetCode] Gas Station 贪心
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...
- github的多环境应用介绍
ssh认证中公钥如同家里大门,私钥就是钥匙,一个大门可以有多把钥匙,大门可以随便展示,钥匙却不能,必须给那些需要的人.其中,公钥的默认名字是id_rsa.pub,私钥的默认名字是id_rsa,它的权限 ...
- CocoaPods Setting up CocoaPods master repo无反应时的处理
Setting up CocoaPods master repo,半天没有任何反应.原因无他,因为那堵墙阻挡了cocoapods.org...gitcafe和oschina都是国内的服务器,可以用它们 ...
- python 锁 多进程
参考: http://www.cnblogs.com/huxi/archive/2010/06/26/1765808.html http://linhs.blog.51cto.com/370259/1 ...
- 从壹开始 [ Ids4实战 ] 之四 ║ 用户数据管理 & 前后端授权联调
前言 哈喽~~~ 大家周一好!夏天到了,大家舒服了没有,熟话说,打败你的不是天真,是天真热!
- MySQL 如何优化cpu消耗
目录 谁在消耗cpu? 祸首是谁? 用户 IO等待 产生影响 如何减少CPU消耗? 减少等待 减少计算 升级cpu 谁在消耗cpu? 用户+系统+IO等待+软硬中断+空闲 祸首是谁? 用户 用户空间C ...
- Algorithm | hash
A basic requirement is that the function should provide a uniform distribution of hash values. A non ...