zoukankan      html  css  js  c++  java
  • Android中Intent传递对象的两种方法:Serializable & Parcelable

    Android中Intent传递对象的有两种方法:
    1.Bundle.putSerializable(Key,Object);
    2.Bundle.putParcelable(Key, Object);

    public class xx implements Serializable {

    }

    public class Book implements Parcelable {
    private String bookName;
    private String author;
    private int publishTime;

    public static final Parcelable.Creator<Book> CREATOR = new Creator<Book>() {
    public Book createFromParcel(Parcel source) {
    Book mBook = new Book();
    mBook.bookName = source.readString();
    mBook.author = source.readString();
    mBook.publishTime = source.readInt();
    return mBook;
    }
    public Book[] newArray(int size) {
    return new Book[size];
    }
    };

    public int describeContents() {
    return 0;
    }

    public void writeToParcel(Parcel parcel, int flags) {
    parcel.writeString(bookName);
    parcel.writeString(author);
    parcel.writeInt(publishTime);
    }
    }

    // Bundle.putSerializable(Key,Object);
    Person mPerson = new Person();
    mPerson.setName("xxx");
    Intent mIntent = new Intent(this, Obj.class);
    Bundle mBundle = new Bundle();
    mBundle.putSerializable(Key, mPerson);
    mIntent.putExtras(mBoundle);

    // Bundle.putParcelable(Key, Object);
    Book mBook = new Book();
    mBook.setBookName("Awefw");
    mBook.setAuthor("xx");
    mBook.setPublishTime("235");
    Intent mIntent = new Intent(this, xx.class);
    Bundle mBundle = new Bundle();
    mBundle.putParcelable(key, mBook);
    mIntent.putExtras(mBundle);
    startActivity(mIntent);

  • 相关阅读:
    Oracle 10g 体系结构及安全管理
    Oracle 10g数据库概述
    jQuery Ajax应用
    ASP.NET Ajax核心对象
    ASP.NET XML
    jQuery插件的使用和编写
    jQuery中的Ajax应用
    弹窗下面的页面滚动问题
    报文过长,华为手机自动拦截报文
    手机抓包 配置步骤
  • 原文地址:https://www.cnblogs.com/bluestorm/p/3739110.html
Copyright © 2011-2022 走看看