Questions tagged [parcelable]

parcelable refers to the capability of an object to be converted to a parcel, a container for reading and writing data of various type, using type specific rather than generic serialization

parcelable is defined in the Android API as as interface for classes whose instances can be written to and restored from a parcel

References

1664 questions
65
votes
7 answers

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

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…
Kitesurfer
  • 3,438
  • 2
  • 29
  • 47
65
votes
4 answers

How to serialize null value when using Parcelable interface

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); …
igor.beslic
  • 954
  • 2
  • 9
  • 16
64
votes
3 answers

Parcelable and inheritance in Android

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 { …
Vincent Mimoun-Prat
  • 28,208
  • 16
  • 81
  • 124
61
votes
10 answers

Problem unmarshalling parcelables

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…
Jeremy Logan
  • 47,151
  • 38
  • 123
  • 143
57
votes
4 answers

Is using Serializable in Android bad?

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…
Alpha Hydrae
  • 2,891
  • 6
  • 26
  • 24
53
votes
4 answers

How to save custom ArrayList on Android screen rotate?

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…
Kalina
  • 5,504
  • 16
  • 64
  • 101
52
votes
21 answers

How to pass ArrayList of Objects from one to another activity using Intent in android?

I have the following in code in my onClick() method as List mQuestionsList = QuestionBank.getQuestions(); Now I have the intent after this line, as follows : Intent resultIntent = new Intent(this, ResultActivity.class); …
RajeshVijayakumar
  • 10,281
  • 11
  • 57
  • 84
48
votes
2 answers

How to marshall and unmarshall a Parcelable to a byte array with help of Parcel?

I want to marshall and unmarshall a Class that implements Parcelable to/from a byte array. I am well aware of the fact that the Parcelable representation is not stable and therefore not meant for long term storage of instances. But I have a use case…
Flow
  • 23,572
  • 15
  • 99
  • 156
46
votes
12 answers

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

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…
4ntoine
  • 19,816
  • 21
  • 96
  • 220
43
votes
7 answers

Passing JSONObject into another activity

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…
Cavachon
  • 2,819
  • 4
  • 21
  • 20
43
votes
4 answers

Android Unit Testing: Bundle/Parcelable

How do you unit test Parcelable? I created a Parcelable class, and wrote this unit test TestClass test = new TestClass(); Bundle bundle = new Bundle(); bundle.putParcelable("test", test); TestClass testAfter =…
garbagecollector
  • 3,731
  • 5
  • 32
  • 44
42
votes
5 answers

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

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…
AndreaF
  • 11,975
  • 27
  • 102
  • 168
41
votes
7 answers

How to make a class with nested objects Parcelable

I'd like to make class A Parcelable. public class A { public String str; public ArrayList list; } This is what I've come up with so far. However it crashes with a NullPointerException. The problem are these two statements:…
Snæbjørn
  • 10,322
  • 14
  • 65
  • 124
40
votes
8 answers

Extract notification text from parcelable, contentView or contentIntent

So I got my AccessibilityService working with the following code: @Override public void onAccessibilityEvent(AccessibilityEvent event) { if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) { …
Force
  • 6,312
  • 7
  • 54
  • 85
38
votes
6 answers

Migrate to the new kotlin-parcelize

Can anyone please explain how to migrate to the new kotlin-parcelize? I tried: Replace apply plugin: 'kotlin-android-extensions' with apply plugin: 'kotlin-parcelize' in app build.gradle Replace import kotlinx.android.parcel.Parcelize with import…
stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270