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传值传对象跳转的更多相关文章

  1. uniapp uni.navigateTo 传值传对象

    uni.navigateTo({ url: '/pages/details?obj='+ encodeURIComponent(JSON.stringify(item)) }); 接收: onLoad ...

  2. intent传对象

    intent还有一个很好用的地方,就是传输对象,但要注意的是这里的传输只是将对象复制了一份通过intent进行传递,并不能达到实时更新的效果,也就是这个对象等偏重于“读”.intent对这个对象有着严 ...

  3. Android 通过 Intent 传递类对象或list对象

    (转:http://www.cnblogs.com/shaocm/archive/2013/01/08/2851248.html) Android中Intent传递类对象提供了两种方式一种是 通过实现 ...

  4. Intent之前的对象传递与fragment传递数据

    Android中Intent传递类对象提供了两种方式一种是 通过实现Serializable接口传递对象,一种是通过实现Parcelable接口传递对象. 要求被传递的对象必须实现上述2种接口中的一种 ...

  5. Android 通过 Intent 传递类对象

    Android中Intent传递类对象提供了两种方式一种是 通过实现Serializable接口传递对象,一种是通过实现Parcelable接口传递对象. 要求被传递的对象必须实现上述2种接口中的一种 ...

  6. Android 开发笔记——通过 Intent 传递类对象

    Android中Intent传递类对象提供了两种方式一种是 通过实现Serializable接口传递对象,一种是通过实现Parcelable接口传递对象. 要求被传递的对象必须实现上述2种接口中的一种 ...

  7. android通过 Intent 传递类对象

    Android中Intent传递类对象提供了两种方式一种是 通过实现Serializable接口传递对象,一种是通过实现Parcelable接口传递对象. 要求被传递的对象必须实现上述2种接口中的一种 ...

  8. android中用Intent传数据,如果用传递的是一个类,就将类实现Parcelable接口

    Parcelable,内存单位,跨进程使用,或者intent传递对象的时候使用.android中用Intent传数据,如果用传递的是一个对象,就将对象实现Parcelable接口,而不是将对象序列化. ...

  9. intent 传参数

    一.传递List<String>和List<Integer>以下以传递List<String>为例,发送List<String>语法为:intent.p ...

随机推荐

  1. 禁用jQuery chosen的选择下拉菜单

    想法是启用被勾掉之后,左侧下拉框禁用.这是chosen()的 disabled之后需要更新一下.就这样,还有别的方法的话请分享,O(∩_∩)O哈哈~

  2. idea下的hibernate反向生成插件

    阅读目录 1. 打开 DataBase 窗口,添加数据源 2. 添加 hibernate 持久层支持,生成实体 Bean /配置文件 谈起 Hibernate 应该得知道 Gavin King 大叔, ...

  3. 2018 ACM南京网络赛H题Set解题报告

    题目描述 给定\(n\)个数$a_i$,起初第\(i\)个数在第\(i\)个集合.有三种操作(共\(m\)次): 1 $u$ $v$ 将第$u$个数和第$v$个数所在集合合并 2 $u$ 将第$u$个 ...

  4. [SDOI2009][bzoj1878] HH的项链 [莫队模板题]

    题面: 传送门 思路: 就是一道莫队的模板题目...... 开一个1000000的数组记录每个数出现的次数,然后每次从1到0或者从0到1更新答案 莫队讲解看这里:莫队 Code: #include&l ...

  5. SQL死锁

    我们操作数据库大量数据时,可能会出现死锁现象. 所谓死锁: 是指两个或两个以上的进程在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用,它们都将无法推进下去.此时称系统处于死锁状态或系统 ...

  6. Error:Cannot find module 'stylus'

    在webpack 里面用了 stylus-loader,但npm instatll 没有正确安装,出现error: Cannot find module ‘stylus’. 解决办法: 重新npm i ...

  7. bzoj 2563 贪心 思想

    BZOJ2563阿狸和桃子的游戏   2563: 阿狸和桃子的游戏 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 952  Solved: 682[Su ...

  8. 自己搭建了一个blog

    https://svtt.sinaapp.com 利用JustWriting开源项目搭建的,不过还是有些许问题.但是考虑到自己的blog好处多多,暂且用着--有时间或者乐趣来了,自己再用wordpre ...

  9. bat文件【java调用】

    Runtime.getRuntime().exec("cmd /c del c:\\a.doc");   //Runtime.getRuntime().exec("not ...

  10. one pragmatical sqlhelper

    namespace ConsoleApplication2 { using System; using System.Collections.Generic; using System.Linq; u ...