バンドルで別のパーセルオブジェクト内でパーセルされた配列オブジェクトを送受信しようとしています。 PARCELED BookオブジェクトBook.javaAndroid - 入れ子になったパーセルオブジェクトを送受信する方法 "バンドル"
public class Book implements Parcelable {
public int id;
public String title;
public Author[] authors;
public String isbn;
public String price;
private Book(Parcel in) {
this.id = in.readInt();
this.title = in.readString();
in.readTypedArray(authors, Author.CREATOR);
this.isbn = in.readString();
this.price = in.readString();
}
public void writeToParcel(Parcel out, int flags) {
out.writeInt(this.id);
out.writeString(this.title);
out.writeArray(this.authors);
out.writeString(this.isbn);
out.writeString(this.price);
}
public int describeContents(){
return 0;
}
public static final Parcelable.Creator<Book> CREATOR = new Parcelable.Creator<Book>() {
@Override
public Book createFromParcel(Parcel in) {
return new Book(in);
}
@Override
public Book[] newArray(int size) {
return new Book[size];
}
};
public Book(int id, String title, Author[] author, String isbn, String price) {
this.id = id;
this.title = title;
this.authors = author;
this.isbn = isbn;
this.price = price;
}
:PARCELED ARRAYはAuthor.java
public class Author implements Parcelable {
public String firstName;
public String middleInitial;
public String lastName;
public Author() {
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeString(this.firstName);
out.writeString(this.middleInitial);
out.writeString(this.lastName);
}
private Author(Parcel in) {
this.firstName = in.readString();
this.middleInitial = in.readString();
this.lastName = in.readString();
}
public int describeContents(){
return 0;
}
public static final Parcelable.Creator<Author> CREATOR = new Parcelable.Creator<Author>() {
@Override
public Author createFromParcel(Parcel in) {
return new Author(in);
}
@Override
public Author[] newArray(int size) {
return new Author[size];
}
};
public String toString() {
StringBuffer sb = new StringBuffer();
if (firstName != null && !"".equals(firstName)) {
sb.append(firstName);
sb.append(' ');
}
if (middleInitial != null && !"".equals(middleInitial)) {
sb.append(middleInitial);
sb.append(' ');
}
if (lastName != null && !"".equals(lastName)) {
sb.append(lastName);
}
return sb.toString();
}
}
コードをオブジェクト:アレイは
コード長の問題を有する
常に、 }
コールとオブジェクトを作成します。
Book new_book = new Book(1, title, authors.parseAuthors(author), isbn, "35$");
Intent i = new Intent(this, BookActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelable("key", new_book);
i.putExtras(bundle);
startActivity(i);
をリモートアクティビティ "BOOK ACTIVITY.CLASS"
Bundle bundle = getIntent().getExtras();
Book book = bundle.getParcelable("key");
任意のアイデアを、どのように私はこの問題を解決することができますか。?バンドル内でネストされています。また、私は著者オブジェクト上でパーセル可能な配列を読み込むための正しい方法を使用していると確信しています。
おかげで、
この「out.writeArray()」を「out.writeTypedArray()」に変更しました。私はそれを修正しました –