zoukankan      html  css  js  c++  java
  • android bundle存放数据详解

    转载自:android bundle存放数据详解

    正如大家所知道,Activity之间传递数据,是将数据存放在Intent或者Bundle中

    例如:

    将数据存放倒Intent中传递:

    将数据放到Bundle中传递:

    但是Intent或者Bundle存放的数据类型是有限的

    我想大家都遇到过这个问题,无法将Map、List<Map<String,Object>>等类型数据存放到Bundle或者Intent中

    但是大家是否注意到,Bundle或者Intent允许存放对象数据

    我们可以从这点着手,我们只要将需要存放到数据先存到一个对象中,再将这个对象存放到Bundle或者Intent中,我们就能成功将想传递到数据传递过去

    操作步骤:

    新建一个类

    将数据存放到对象中,再将对象放到Bundle中进行传递

    Intent intent = new Intent(MainActivity.this,SecondActivity.class);
    Bundle bundle = new Bundle();
    Map<String,Objects> map = new HashMap<String,Objects>();
    map.put("wenhou","你好");
    map.put("name", "jason");
    map.put("age", 25);
    Data data = new Data();
    data.setMap(map);
    bundle.putSerializable("data",data);
    intent.putExtras(bundle);
    startActivity(intent);
     
     
  • 相关阅读:
    [HEOI2015]兔子与樱花
    [HNOI2015]亚瑟王
    [JSOI2011]分特产
    某考试 T3 sine
    [JSOI2015]最小表示
    51NOD 1258 序列求和 V4
    Codeforces 622F The Sum of the k-th Powers
    Loj #6261. 一个人的高三楼
    [HAOI????] 硬币购物
    bzoj4318 OSU!
  • 原文地址:https://www.cnblogs.com/mukekeheart/p/5786610.html
Copyright © 2011-2022 走看看