parcelable

Abstract class as parcelable

与世无争的帅哥 提交于 2019-11-28 02:38:51
问题 Basicly I have the following structure in my app: It would be straightforward to implement such a structure without the abstract class ProjectItem , but in this case I don't know how to implement this. The abstract class ProjectItem needs a CREATOR as it should be parcelable. (like in.readTypedList(mProjectItems, ProjectItem.CREATOR); within the constructor Project(Parcel in)) But in fact, the CREATOR can only be implemented in its derived classes for logical reasons. So, how to implement

Android Parcelable and Serializable

只谈情不闲聊 提交于 2019-11-27 21:05:24
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 Person class is the following: public class PersonTwo { MyCustomObj customObj; String name; int Age; ...

How to fix Unmarshalling unknown type code XXX at offset YYY in Android?

北城以北 提交于 2019-11-27 20:05:24
I'm having app crash on resume because of Unmarshalling exception. I've checked all the Serializables have constructor with no parameters and even checked all the serializables using ObjectStream (save to file and load from file). How can i understand actual class type for parcelable offset that cause exception: Parcel android.os.Parcel@42209460: Unmarshalling unknown type code 2131165303 at offset 3748 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2080) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2105) at android.app.ActivityThread.access

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

筅森魡賤 提交于 2019-11-27 18:27:07
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) instead of this method, since the Bundle class provides a type-safe API that allows you to avoid mysterious

How to use Parcelable in fragment for getting data?

社会主义新天地 提交于 2019-11-27 17:52:42
问题 I can use Parcelable in Activity but I don't know how to use it in Fragment. I have a ListFragment in FragmentGet to display all rows database in ListView, I want to get details of ListView in another Fragment when it's clicked, I use Parcelable to passing data between Fragments. This is my Test.java: import android.os.Parcel; import android.os.Parcelable; public class Test implements Parcelable { private int studentNumber; private String studentName; private String studentFamily; public int

How to make a class with nested objects Parcelable

一笑奈何 提交于 2019-11-27 17:43:11
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-generated method stub return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest

Android ArrayList<MyObject> pass as parcelable

谁说我不能喝 提交于 2019-11-27 13:57:08
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 data. Am i correct creating a LocalityList class for the ArrayList and making that parcelable, or should

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

耗尽温柔 提交于 2019-11-27 13:52:47
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); details.putExtra("Car", parcelableExtra); startActivity(dettagli); And I try to load the extra with

what is difference between Parcelable and Serialization used in android

≯℡__Kan透↙ 提交于 2019-11-27 12:46:39
问题 I want to know exact , whether should I used parcelable or serialization technique for sending data from one activity to other? is it compulsory to use one of them for sending data from one to other? when should I use them? and the exact difference between them and performance of both of them in java aspects. Thanks in advance. public class GetSetClass implements Serializable { private int dt = 10; /** pass any object, drwabale */ public int getDt() { return dt; } public void setDt(int dt) {

Android, How to use readTypedList method correctly in a Parcelable class?

痞子三分冷 提交于 2019-11-27 11:32:27
问题 I have two Activities, in the first one, I instanciate an ArrayList of Object myObject. In the second activity, i need to get this Arraylist. I've found a tutorial : http://prasanta-paul.blogspot.com/2010/06/android-parcelable-example.html I have implemented my class liked it's explain. public class Chapitre implements Parcelable{ private int numero; private String titre; private String description; private int nbVideo; private ArrayList<Video> listeVideo; public Chapitre(int numero, String