parcelable

Android - Implementing Parcelable Inner Class

天大地大妈咪最大 提交于 2019-12-04 06:34:58
问题 I know how to implement a simple Parcelable class with public variables but the class below is somewhat more complex. How can I implement the Parcelable interface given that this class has an inner class and ListEntity? I'm not even sure how to begin. Any detailed information on how to do this would be greatly appreciated. import android.os.Parcel; import android.os.Parcelable; import java.util.List; public class ResponsePlaceSearch implements Parcelable { // *** Parcelable methods are shown

Use Parcelable to pass an object from one android activity to another

我是研究僧i 提交于 2019-12-04 06:01:49
I want to do this class A extends Activity{ private class myClass{ } myClass obj = new myClass(); intent i = new Intent(); Bundle b = new Bundle(); b.putParcelable(Constants.Settings, obj); //I get the error The method putParcelable(String, Parcelable) in the type Bundle is not applicable for the arguments (int, A.myClass) i.setClass(getApplicationContext(),B.class); startActivity(i); } How do I use Parcelable to pass obj to activity B? As the error suggests, you need to make your class ( myClass in this case) implement Parcelable . If you look at the documentation for Bundle , all the

Getting NullPointerException: Attempt to get length of null array in Parcelable when trying to read a byte array in Android

邮差的信 提交于 2019-12-04 04:56:11
I have a class that implements the Parcelable. All my values are set ok through the writeToParcel method but when reading within the constructor I have a problem with a byte array that throws NullPointerException: public final class Product implements Parcelable { private Integer ID; private byte[] image; // Constructors public Product(){} public Product(Parcel source) { this.ID = source.readInt(); source.readByteArray(this.image); } public int describeContents() { return this.hashCode(); } public void writeToParcel(Parcel dest, int flags) { dest.writeInt(this.ID); dest.writeByteArray(this

How to use Parcel.readTypedList() along with @Parcelize from kotlin-android-extensions?

偶尔善良 提交于 2019-12-04 04:35:17
问题 I'm running into a problem with implementing Parcelable-based state persistence in a View. Namely, as I need to implement the methods of BaseSavedState like this: class SavedState : BaseSavedState { lateinit var myList: ArrayList<MyParcelable> constructor(superState: Parcelable) : super(superState) {} private constructor(parcel: Parcel) : super(parcel) { val listSize = parcel.readInt() val list = ArrayList<MyParcelable>(listSize) this.myList = parcel.readTypedList(list, /* needs MyParcelable

java.lang.RuntimeException: Parcel android.os.Parcel: Unmarshalling unknown type code

谁说我不能喝 提交于 2019-12-04 00:02:11
问题 I seem to be getting a strange error in my app (see GitHub), which occurs when I pass objects to different activities that implement Parcelable . I have checked other questions and answers here on Stack Overflow, but I was unable to find a solution. I've tried the answer here, for example - here it is for reference: -keepclassmembers class * implements android.os.Parcelable { static ** CREATOR; } I've also made sure that the method calls in writeToParcel are in order. Most other questions on

Make a class parcelable which contains Custom object list

╄→尐↘猪︶ㄣ 提交于 2019-12-03 16:49:31
I am getting error while making a list object parsable(i think the error occured while reading the object) here is my code public class TestSample implements Parcelable { int intValue; String stirngValue; private List<DocumentControlPolicy> cpls; @Override public int describeContents() { // TODO Auto-generated method stub return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(intValue); dest.writeString(stirngValue); dest.writeTypedList(cpls); dest.writeList(cpls); } public static final Parcelable.Creator<TestSample> CREATOR = new Parcelable.Creator<TestSample>

Passing a Cursor between processes (Parcelable Cursor)

一个人想着一个人 提交于 2019-12-03 16:02:50
I need to pass a Cursor ( SQLiteCursor ) from a service to an application on API 10 , and having hard time finding a decent (and fast) solution. I've seen the CursorWindow class. This is Parcelable but I can't instantiate this class on API 10 to use SQLiteCursor.fillWindow() because it has no valid constructors. CursorWindow(boolean) is deprecated. And even if I got a CursorWindow instance with data from a SQLiteCursor , how do I copy this window into a new Cursor ? What Cursor implementation should I use for this? I see no usable Cursor that extends AbstractWindowedCursor . Thanks for your

Does retrieving a parcelable object through bundle always create new copy?

≯℡__Kan透↙ 提交于 2019-12-03 12:21:54
I'm passing a parcelable object to a fragment by adding into a bundle while creating the fragment. In onc instance modification to this parcelled object reflects modification in original object and in another case it is not. I'm a little baffled by this behaviour. Till now I have assumed retrieving a parcelled objects through a bundle always create new object[no sure whether it's shallow copy or deep copy]. Someone please clarify parcelable behaviour. I was struggling with a similar issue. At the first glance it seems that we always obtain a new deep copy from the parcelled objects. Moreover,

Using Parcelable with circular references

半城伤御伤魂 提交于 2019-12-03 10:42:38
问题 It appears that Parcelable doesn't gracefully handle circular references like Serializable does. In the following example, the Serialization of Bar works just fine, but writing it to a Parcel causes a stackoverflow: I/TestRunner( 1571): java.lang.StackOverflowError I/TestRunner( 1571): at android.os.Parcel.writeParcelable(Parcel.java:1106) I/TestRunner( 1571): at android.os.Parcel.writeValue(Parcel.java:1029) I/TestRunner( 1571): at com.XXX.util.ParcelableTest$Bar.writeToParcel(ParcelableTest

Passing ArrayList<CustomObject> Between Activities

我的未来我决定 提交于 2019-12-03 08:37:03
i've implemented a Parcelable class: public class Evento implements Parcelable { private int; private String ; private String imagen; //more atts //Constructors, setters and getters public Evento(Parcel in) { this.id = in.readInt(); this.titulo = in.readString(); this.imagen=in.readString(); public void writeToParcel(Parcel dest, int flags) { dest.writeInt(id); dest.writeString(titulo); dest.writeString(imagen); } public static final Parcelable.Creator<Evento> CREATOR = new Parcelable.Creator<Evento>() { @Override public Evento createFromParcel(Parcel in) { return new Evento(in); } @Override