zoukankan      html  css  js  c++  java
  • 每日总结

    1.今天开始学习Intent之复杂数据的传递

    Intent传递数组 bd.putStringArray("StringArray"

    读取数组:String[] str = bd.getStringArray("StringArray")

    Intent传递集合

    写入集合:

    intent.putStringArrayListExtra(name, value)
    intent.putIntegerArrayListExtra(name, value)

    读取集合:

    intent.getStringArrayListExtra(name)
    intent.getIntegerArrayListExtra(name)

    将对象转换为Json字符串

    Model:

    public class Book{
        private int id;
        private String title;
        //...
    }
    
    public class Author{
        private int id;
        private String name;
        //...
    }

    写入数据:

    Book book=new Book();
    book.setTitle("Java编程思想");
    Author author=new Author();
    author.setId(1);
    author.setName("Bruce Eckel");
    book.setAuthor(author);
    Intent intent=new Intent(this,SecondActivity.class);
    intent.putExtra("book",new Gson().toJson(book));
    startActivity(intent);

    读取数据:

    String bookJson=getIntent().getStringExtra("book");
    Book book=new Gson().fromJson(bookJson,Book.class);
    Log.d(TAG,"book title->"+book.getTitle());
    Log.d(TAG,"book author name->"+book.getAuthor().getName());
     
  • 相关阅读:
    2019年10月24日打印个人信息清单
    vsftp安装
    网络连接
    mysql多种方法修改密码----5.6的坑
    openstack-L版安装
    openstack是什么
    kvm快照
    文件操作
    函数
    virt-manage图形界面键盘错位问题
  • 原文地址:https://www.cnblogs.com/chenghaixiang/p/14909423.html
Copyright © 2011-2022 走看看