parcelable

How to send objects through bundle

会有一股神秘感。 提交于 2019-11-26 19:39:29
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 ? 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 thing that can go through bundles is plain data - everything else is based on interpretations of what that data

Unmarshalling errors in Android app with custom parcelable classes

前提是你 提交于 2019-11-26 19:31:18
问题 For my Android application, I get several unmarshalling errors although I think I've done everything that is needed to properly save and load objects via Parcelable s. Can you tell me what's wrong with my code? Error 1: java.lang.RuntimeException: Unable to start activity ComponentInfo Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@41279860: Unmarshalling unknown type code 6619241 at offset 1372 at android.os.Parcel.readValue(Parcel.java:1922) at android.os.Parcel

Is using Serializable in Android bad?

一世执手 提交于 2019-11-26 18:30:34
I've been reading a lot of posts and articles extolling the speed of Parcelable over Serializable. I've been using both for a while to pass data between Activities through Intents, and have yet to notice any speed difference when switching between the two. The typical amount of data I have to transfer is 5 to 15 nested objects with 2 to 5 fields each. Since I have about 30 classes which must be transferable, implementing Parcelable requires a lot of boilerplate code that adds maintenance time. One of my current requirements is also that the compiled code should be as small as possible; I

Cannot pass custom Object in an Intent: The Method Put Extra is Ambiguous for the type Intent

…衆ロ難τιáo~ 提交于 2019-11-26 18:19:54
问题 If I try to write Car myCarObject=getCar(); Intent details = new Intent(Start.this, DetailsCar.class); details.putExtra("Car", myCarObject); startActivity(details); Eclipse show me a compilation error "The Method Put Extra is Ambiguous for the type Intent" in the line details.putExtra("Car", myCarObject); If I use the code Car myCarObject=getCar(); ArrayList<Car> parcelableExtra = new ArrayList<Car>(); parcelableExtra.add(myCarObject); Intent details = new Intent(Start.this, DetailsCar.class)

how to properly implement Parcelable with an ArrayList<Parcelable>?

♀尐吖头ヾ 提交于 2019-11-26 17:15:32
I am having trouble making my class Parcelable . The trouble is, I am trying to write to the parcel a member in the class which is an ArrayList<Parcelable> object. The ArrayList is Serializable , and the objects ( ZigBeeDev ) in the list are Parcelable . Here is the relevant code: package com.gnychis.coexisyst; import java.util.ArrayList; import java.util.Iterator; import android.os.Parcel; import android.os.Parcelable; public class ZigBeeNetwork implements Parcelable { public String _mac; // the source address (of the coordinator?) public String _pan; // the network address public int _band;

Read & writing arrays of Parcelable objects

爱⌒轻易说出口 提交于 2019-11-26 17:07:42
I have following class which reads and writes an array of objects from/to a parcel: class ClassABC extends Parcelable { MyClass[] mObjList; private void readFromParcel(Parcel in) { mObjList = (MyClass[]) in.readParcelableArray( com.myApp.MyClass.class.getClassLoader())); } public void writeToParcel(Parcel out, int arg1) { out.writeParcelableArray(mObjList, 0); } private ClassABC(Parcel in) { readFromParcel(in); } public int describeContents() { return 0; } public static final Parcelable.Creator<ClassABC> CREATOR = new Parcelable.Creator<ClassABC>() { public ClassABC createFromParcel(Parcel in)

Android ArrayList<MyObject> pass as parcelable

北城余情 提交于 2019-11-26 16:33:11
问题 Code now modified to reflect the accepted solution. This now serves as a working example of how to pass a custom ArrayList into a DialogFragment. I am passing an ArrayList of custom objects to a DialogFragment using a Bundle on newInstance. The arraylist is received correctly in newInstance. The call to putParcelable executes fine (no errors), but putting breakpoints in the parcelable code in the ArrayList object shows that the parcel methods are not been called when setting or getting the

Android: How to pass Parcelable object to intent and use getParcelable method of bundle?

有些话、适合烂在心里 提交于 2019-11-26 15:24:30
Why bundle has getParcelableArrayList , getParcelable methods; but Intent has only putParcelableArrayListExtra method? Can I transmit only object<T> , not ArrayList of one element? Then, what is getParcelable for? yorkw Intent provides bunch of overloading putExtra() methods. Suppose you have a class Foo implements Parcelable properly, to put it into Intent in an Activity: Intent intent = new Intent(getBaseContext(), NextActivity.class); Foo foo = new Foo(); intent.putExtra("foo ", foo); startActivity(intent); To get it from intent in another activity: Foo foo = getIntent().getExtras()

Passing JSONObject into another activity

二次信任 提交于 2019-11-26 12:42:26
问题 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

How to save custom ArrayList on Android screen rotate?

旧时模样 提交于 2019-11-26 12:10:33
I have an ArrayList with custom objects that I would like to be able to save and restore on a screen rotate. I know that this can be done with onSaveInstanceState and onRestoreInstanceState if I were to make the ArrayList its own class, which implements either Parcelable or Serializable ... But is there a way to do this without creating another class? You do not need to create a new class to pass an ArrayList of your custom objects. You should simply implement the Parcelable class for your object and use Bundle#putParcelableArrayList() in onSaveInstanceState() and onRestoreInstanceState() .