parcelable

Class not found when Unmarshalling Android Intent Parcelable

天大地大妈咪最大 提交于 2019-12-18 04:32:07
问题 I have a ArrayList that I am passing between activities . In this ArrayList are objects made from a class that has four variables in it. One of those variables is another ArrayList<object> that is from another class . I have implemented Parcelable on both and am pretty sure I have completed the parcelable methods properly. Here are the errors: Errors: 03-18 02:37:27.063: D/dalvikvm(3249): GC_FOR_ALLOC freed 82K, 6% free 3020K/3180K, paused 1ms, total 3ms 03-18 02:37:27.093: I/dalvikvm-heap

Is there a convenient way to create Parcelable data classes in Android with Kotlin?

浪子不回头ぞ 提交于 2019-12-17 22:29:31
问题 I'm currently using the excellent AutoParcel in my Java project, which facilitates the creation of Parcelable classes. Now, Kotlin, which I consider for my next project, has this concept of data classes, that automatically generate the equals, hashCode and toString methods. Is there a convenient way to make a Kotlin data class Parcelable in a convenient way (without implementing the methods manually)? 回答1: Kotlin 1.1.4 is out Android Extensions plugin now includes an automatic Parcelable

Write a sub class of Parcelable to another Parcel

情到浓时终转凉″ 提交于 2019-12-17 21:48:20
问题 I have a class that implements Parcelable interface: class A implements Parcelable { } I have another class B that contains an A object as an instance variable. In the writeToPacel inside class B , I want to write object B to the Parcel : class B implements Parcelable{ public void writeToParcel(Parcel dest, int flags) { dest.write ??? } } How can I write and read it? 回答1: class B implements Parcelable{ //lets assume you have A as a data member A obj; public void writeToParcel(Parcel dest, int

Arraylist in parcelable object

落花浮王杯 提交于 2019-12-17 17:37:05
问题 I have seen many parcelable examples so far, but for some reason I can't get it to work when it gets a bit more complex. I have a Movie object, which implements Parcelable. This book object contains some properties, such as ArrayLists. Running my app results in a NullPointerException when executing the ReadTypedList ! I'm really out of ideas here public class Movie implements Parcelable{ private int id; private List<Review> reviews private List<String> authors; public Movie () { reviews = new

How write Java.util.Map into parcel in a smart way?

让人想犯罪 __ 提交于 2019-12-17 15:32:11
问题 I have a Generic Map of Strings (Key, Value) and this field is part of a Bean which I need to be parcelable. So, I could use the Parcel#writeMap Method. The API Doc says: Please use writeBundle(Bundle) instead. Flattens a Map into the parcel at the current dataPosition(), growing dataCapacity() if needed. The Map keys must be String objects. The Map values are written using writeValue(Object) and must follow the specification there. It is strongly recommended to use writeBundle(Bundle)

Parcelable where/when is describeContents() used?

☆樱花仙子☆ 提交于 2019-12-17 10:18:09
问题 Does anyone know where/when this method of a Parcelable is called? @Override public int describeContents() { return 0; } It has to be overriden. But should I consider doing something useful with it? 回答1: There is a constant defined in Parcelable called CONTENTS_FILE_DESCRIPTOR which is meant to be used in describeContents() to create bitmask return value. Description for CONTENTS_FILE_DESCRIPTOR in the API ref is: Bit masks for use with describeContents(): each bit represents a kind of object

Pass ArrayList<? implements Parcelable> to Activity

百般思念 提交于 2019-12-17 05:55:10
问题 I have searched a few topics but not found a solution to my problem. public class Series implements Parcelable { private String name; private int numOfSeason; private int numOfEpisode; /** Constructors and Getters/Setters have been removed to make reading easier **/ public Series(Parcel in) { String[] data = new String[3]; in.readStringArray(data); this.name = data[0]; this.numOfSeason = Integer.parseInt(data[1]); this.numOfEpisode = Integer.parseInt(data[2]); } @Override public int

Pass ArrayList<? implements Parcelable> to Activity

柔情痞子 提交于 2019-12-17 05:54:53
问题 I have searched a few topics but not found a solution to my problem. public class Series implements Parcelable { private String name; private int numOfSeason; private int numOfEpisode; /** Constructors and Getters/Setters have been removed to make reading easier **/ public Series(Parcel in) { String[] data = new String[3]; in.readStringArray(data); this.name = data[0]; this.numOfSeason = Integer.parseInt(data[1]); this.numOfEpisode = Integer.parseInt(data[2]); } @Override public int

How to send objects through bundle

元气小坏坏 提交于 2019-12-17 04:46:57
问题 I need to pass a reference to the class that does the majority of my processing through a bundle. The problem is it has nothing to do with intents or contexts and has a large amount of non-primitive objects. How do I package the class into a parcelable/serializable and pass it to a startActivityForResult ? 回答1: Figuring out what path to take requires answering not only CommonsWare's key question of "why" but also the question of "to what?" are you passing it. The reality is that the only

Nested Class Parcelable [duplicate]

ぃ、小莉子 提交于 2019-12-16 18:02:10
问题 This question already has answers here : How can a Java class have no no-arg constructor? (8 answers) Closed 2 years ago . I need to know how to make a nested class Parcelable . When I create a nested class I get an error (it requires the parcel as a param.) Code: public class BookingDetailsItem implements Parcelable { private ServiceProviderItem serviceProvider; public Appointment appointmentDetails; private String notes; public BookingDetailsItem(ServiceProviderItem serviceProvider) { this