parcelable

Is it possible to parcel a generic class?

十年热恋 提交于 2019-11-30 22:32:25
问题 I'm trying to create public class MyClass<T extends Parcelable> implements Parcelable . I'm having trouble implementing Parcelable . Is it possible to create a generic class that implements Parcelable ? (Note that T is bounded so that it also must implement Parcelable ). I am running into trouble with the fact that the Parcelable interface requires a static variable: public static final Parcelable.Creator<MyParcelable> CREATOR . Thus I cannot do public static final Parcelable.Creator<MyClass

Size limitation on attached Parcelable?

拟墨画扇 提交于 2019-11-30 22:06:51
问题 I want to know is there any size limitation on Parcelable that attached to an Intent ? I Read some docs about Intents , Bundles , Parcelable again and there was nothing about size limitation. But I read some answers, that say size of attached Parcelable is limited (for example, 1 MB). So are Parcelable s limited by size or it only depends to the device? 回答1: Its explained on the docs here. The transaction buffer for each process is 1 mb. In my understanding the factors to be considered are:

Implementing Parcelable Class That Requires Context

試著忘記壹切 提交于 2019-11-30 20:08:05
I'd like for my data class to implement Parcelable so it can be shared between Activities, however it also needs reference to Context so the fields can be saved to SQLiteDatabase. This however is a problem since Parcelable.Creator method createFromParcel only has one parameter Parcel. public abstract class Record implements Parcelable { protected Context context; protected String value; public Record(Context context) { this.context = context; } public Record(Parcel parcel) { this.value = parcel.readString(); } public void save() { //save to SQLiteDatabase which requires Context } @Override

How to Pass Drawable using Parcelable

倖福魔咒の 提交于 2019-11-30 18:02:40
I have a class where i have an Drawable as an member. This class i am using for sending data across activities as an Parcelable extra. For that i have extended the parceble, and implemented the required functions. I am able to send the basic data types using read/write int/string. But i am facing problem while marshaling the Drawable object. For that i tried to convert the Drawable to byte array , but i am getting class cast Exceptions. I am using following code to covert my Drawable to Byte array: Bitmap bitmap = (Bitmap)((BitmapDrawable) mMyDrawable).getBitmap(); ByteArrayOutputStream stream

Android Parcelable - Write and read ArrayList< IA > when IA is a interface

回眸只為那壹抹淺笑 提交于 2019-11-30 17:18:24
I have a interface IA and class B and C that implement them. Both B and C implement Parcelable as well. Then I have the tricky part: Class D has a ArrayList< IA > . I need this too insert both classes B and C in the arraylist . They share the same structure but the "IS-A" relation don't apply. I need to pass D from one activity to another as a Parcel. I've tried to write (ArrayList<IA>) in.readSerializable but I got a IOException . I know that if IA was not a interface the problem was easy, but I can't seem to find an easy solution for this. Any ideas? @SuppressWarnings("unchecked") public D

Why is it possible to write a boolean array to a parcel but not a boolean?

我与影子孤独终老i 提交于 2019-11-30 17:03:35
In the documentation for the Parcel it states a method exists public final void writeBooleanArray (boolean[] val) But there is no method for writeBoolean(boolean val) There also exists: public final void writeLong (long val) public final void writeLongArray (long[] val) So a similar pattern is available for other primitive types. Can some one explain why this is? There is an open bug report on it: http://code.google.com/p/android/issues/detail?id=5973 Evidently others agree with your assessment (and I do too). No reason at all, seems just a miss to me. :-) Write a boolean[1] if you need. See

YouTube Android Player API throws “BadParcelableException ClassNotFoundException when unmarshalling: asc” with new YouTube version

自闭症网瘾萝莉.ら 提交于 2019-11-30 09:45:07
Filing bug to YouTube Android Player API Library engineers: see android-youtube-api tag Over the course of the past week and a half, I've noticed this weird BadParcelableException steadily increasing in our app and have nailed it down to YouTube's new release on android. This crash will occur if your app is playing a youtube video, bringing your app to background, force stopping the Youtube app, and resuming your app again. Crash reproducible on Youtube version 12.19.56. Also tested on an older YouTube version 12.05.21 and the crash was not there. Stack trace: main Exception: Unable to start

Is it possible to create a HashMap that is Parcelable on Android?

不羁岁月 提交于 2019-11-30 08:30:18
I am trying to extend HashMap as a Parcelable and I got the syntax to compile, however, at runtime it throws an exception and returns a null pointer trying to un-marshal the data. The sender has to cast to (Parcelable) to resolve ambiguity, however, the receiver complains that is expected Parcelable but found HashMap. Has anyone been successful with this? Is my syntax wrong? Is there a better solution? Following is the code: HomeActivity.java - the sender ContentViewActivity.java - the receiver ContentItemSimple.java - as its name implies (wraps a String and Integer) ContentItemCollection.java

Implementing Parcelable Class That Requires Context

不问归期 提交于 2019-11-30 04:50:56
问题 I'd like for my data class to implement Parcelable so it can be shared between Activities, however it also needs reference to Context so the fields can be saved to SQLiteDatabase. This however is a problem since Parcelable.Creator method createFromParcel only has one parameter Parcel. public abstract class Record implements Parcelable { protected Context context; protected String value; public Record(Context context) { this.context = context; } public Record(Parcel parcel) { this.value =

Android Parcelable - Write and read ArrayList< IA > when IA is a interface

落花浮王杯 提交于 2019-11-30 00:50:54
问题 I have a interface IA and class B and C that implement them. Both B and C implement Parcelable as well. Then I have the tricky part: Class D has a ArrayList< IA > . I need this too insert both classes B and C in the arraylist . They share the same structure but the "IS-A" relation don't apply. I need to pass D from one activity to another as a Parcel. I've tried to write (ArrayList<IA>) in.readSerializable but I got a IOException . I know that if IA was not a interface the problem was easy,