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系统——软链接、硬链接
区别:硬链接原文件&链接文件公用一个inode号,说明他们是同一个文件,而软链接原文件&链接文件拥有不同的inode号,表明他们是两个不同的文件: 在文件属性上软链接明确写出了是链接文 ...
- MyBatis输出sql需要log4j.properties配置
# Global logging configuration log4j.rootLogger=info,stdout,console,logfile # MyBatis logging config ...
- python知识集合
1.list list是一种有序的集合 例子:classmates = ['Michael', 'Bob', 'Tracy']; 方法:1. len len(classmates) //3 2.app ...
- 集成 Union Pay - 银联支付--ios
请看这个网址,谢谢谢 http://www.cnblogs.com/oc-bowen/p/6000389.html
- 冬训 day2
模拟枚举... A - New Year and Buggy Bot(http://codeforces.com/problemset/problem/908/B) 暴力枚举即可,但是直接手动暴力会非 ...
- [LeetCode] Scramble String 字符串 dp
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- android中提示&对话框----Notification
Notification(状态栏通知) 一.Notification用于状态栏显示通知的控件,在不同的设备上面Notification是不一样的 二.Notification的基本布局 元素组成: I ...
- 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---15
以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:
- Ubuntu 14.04 x64配置Android 4.4 kitkat编译环境的方法
Ubuntu 14.04 x64配置Android 4.4 kitkat编译环境的方法跟Ubuntu 12.04 - 13.10 以及jellybean编译环境配置没多大区别, 顺便记录下而已: Ub ...
- LeetCode OJ-- Distinct Subsequences ** 递推
https://oj.leetcode.com/problems/distinct-subsequences/ 对于string S 和 T求,T 是 S的几种子串. 首先想到了递归方法,列出递归公式 ...