parcelable

Passing JSONObject into another activity

孤街浪徒 提交于 2019-11-27 04:02:05
I'm hitting an external API that's returning JSON data (new dvd titles). I'm able to parse out the JSON and list each dvd title and other dvd information into a ListView just fine. I was also able to setup an onListItemClick method just fine for primitive data (title string). I ended up writing something like so for the onListItemClick method: Just to note, the productArray is a class var that's being set by another method that holds an array of JSONObjects. protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Intent i = new

ClassNotFoundException when unmarshalling: android.support.v4.view.ViewPager$SavedState

青春壹個敷衍的年華 提交于 2019-11-27 03:51:08
问题 I am seeing the following error in my Android crash reports: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: android.support.v4.view.ViewPager$SavedState at android.os.Parcel.readParcelable(Parcel.java:1971) at android.os.Parcel.readValue(Parcel.java:1859) at android.os.Parcel.readSparseArrayInternal(Parcel.java:2128) at android.os.Parcel.readSparseArray(Parcel.java:1581) at android.os.Parcel.readValue(Parcel.java:1916) at android.os.Parcel.readMapInternal(Parcel

Android Class Parcelable with ArrayList

僤鯓⒐⒋嵵緔 提交于 2019-11-27 03:41:30
I have an android project where I have a class. In that class is an ArrayList<Choices> . I will be getting some XML, parsing it out, then making objects out of it which I will be passing to another activity. I'm choosing Parcelable for this. Is Parcelable a good choice? Am I doing everything correctly? I'm not familiar really with Parcelable. My ArrayList is of another class that I made within this class. Will it properly pass that ArrayList of objects to the Parcel with it not extending Parcelable and stuff? import java.util.ArrayList; import android.os.Parcel; import android.os.Parcelable;

android parcelable referencing another parcelable circular dependence

◇◆丶佛笑我妖孽 提交于 2019-11-27 03:27:11
问题 Rather simple scenario really, but I could not find anything related on Google so here goes: class ContainerClass implements Parcelable { List<ItemClass> _items; (...) public void writeToParcel( Parcel p, int args ) { p.writeList( _items ); (...) } } class ItemClass implements Parcelable { ContainerClass _containerRef; (...) public void writeToParcel( Parcel p, int args ) { p.writeParcelable( _containerRef ); (...) } } This will inevitably loop and overflow the stack. My question: How am I

Parcelable and inheritance in Android

99封情书 提交于 2019-11-27 03:10:35
I got an implementation of Parcelable working for a single class that involves no inheritance. I have problems figuring out the best way to implement the interface when it come to inheritance. Let's say I got this : public abstract class A { private int a; protected A(int a) { this.a = a; } } public class B extends A { private int b; public B(int a, int b) { super(a); this.b = b; } } Question is, which is the recommended way to implement the Parcelable interface for B (in A? in both of them? How?) Here is my best solution, I would be happy to hear from somebody that had a thought about it.

I don't get why this ClassCastException occurs

穿精又带淫゛_ 提交于 2019-11-27 02:05:56
问题 // Application ... Intent i = new Intent(); i.putExtra(EXTRA_FILE_UPLOAD_URIS, mGalleryAdapter.getItems()); Uri[] getItems() { return mItems; } // Service ... intent.getParcelableArrayExtra(EXTRA_FILE_UPLOAD_URIS); //works, returns Parcelable[] Uri[] uris = (Uri[])intent.getParcelableArrayExtra(EXTRA_FILE_UPLOAD_URIS); // ... Breaks with ClassCastException Why does the cast to Uri[] break, when Uri is Parcelable ? 回答1: Unfortunately there is no way to cast like that for arrays in Java . You

How to serialize null value when using Parcelable interface

天大地大妈咪最大 提交于 2019-11-27 01:12:26
问题 regarding my code example down, what shold I do if one Locable's variables is null? In example, now if l.getZoom() returns null, I got NullPointerException. @Override public void writeToParcel(Parcel parcel, int arg1) { parcel.writeInt(count); for(Locable l:locableArr){ parcel.writeInt(l.getOriginId()); parcel.writeInt(l.getLocableType()); parcel.writeInt(l.getZoom()); parcel.writeDouble(l.getLatituda()); parcel.writeDouble(l.getLongituda()); parcel.writeString(l.getTitle()); parcel

How to make a class with nested objects Parcelable

青春壹個敷衍的年華 提交于 2019-11-26 22:35:15
问题 I'd like to make class A Parcelable. public class A { public String str; public ArrayList<B> list; } This is what I've come up with so far. However it crashes with a NullPointerException. The problem are these two statements: dest.writeList(list); & in.readList(list, this.getClass().getClassLoader()); . I can't figure out what to do from here :( Class A public class A implements Parcelable { public String str; public ArrayList<B> list; @Override public int describeContents() { // TODO Auto

Android Parcelable and Serializable

丶灬走出姿态 提交于 2019-11-26 20:32:18
问题 So i know it is recommended to use Parcelable instead of Serializable in android, because it is faster. My question is: is that impossible to avoid using Serializable right? If I have a custom object i want to serialize, let's say I have the following class definition public class Person { String name; int Age; ... .... } Making this parcelable is easy, because the Person class contains the types parcel.write*() supports, i.e. there is parcel.writeString and parcel.writeInt Now, what if the

Problem unmarshalling parcelables

你离开我真会死。 提交于 2019-11-26 20:13:32
I've got a few classes that implement Parcelable and some of these classes contain each other as properties. I'm marshalling the classes into a Parcel to pass them between activities. Marshalling them TO the Parcel works fine, but when I try to unmarshall them I get the following error: ... AndroidRuntime E Caused by: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: schemas.Arrivals.LocationType AndroidRuntime E at android.os.Parcel.readParcelable(Parcel.java:1822) AndroidRuntime E at schemas.Arrivals.LayoverType.<init>(LayoverType.java:121) AndroidRuntime E at