parcelable

Storing a Parcelable object to a File in Android

℡╲_俬逩灬. 提交于 2019-12-07 12:04:02
问题 I am trying to store an ArrayList of ResolveInfo objects to a file so that I don't have to rebuild it each time my application launches (about 4-6 seconds) ResolveInfo objects are Parcelable, but not Serializable so I get a java.io error when I try to write the objects. I have stored them in my savedInstanceState bundle, but that doesn't help when closing the application. Am I doing something plain wrong? 回答1: savedInstance info will not save across multiple sessions. You will really want to

Can Nulls be passed to parcel?

柔情痞子 提交于 2019-12-07 07:05:31
问题 Is it possible to write null to Parcel when parcelling an object, and get null back again when unparcelling it again? Let's assume we have the following code: public class Test implements Parcelable { private String string = null; public Test(Parcel dest, int flags) { source.writeString(string); } } Will I get a NullPointerException when reading this value back from the parcel using Parcel.readString() ? Or will I get a null value out? 回答1: Yes, you can pass a null to the Parcel.writeString

Pass parcelable object containing Map between Activity

落爺英雄遲暮 提交于 2019-12-07 05:40:06
问题 My class ExpenseFB , which implements Parcelable , contains a Map of UserFB (which implements Parcelable too): ExpenseFB: public class ExpenseFB implements Parcelable { private String id; private String name; private String description; private String whopaidID; private String whopaidName; private Double amount; private Map<String, UserFB> partecipants; // setters and getters... @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) {

adding parcelable to an interface class for custom objects

◇◆丶佛笑我妖孽 提交于 2019-12-07 03:08:08
问题 I have a custom object class but that is implemented through an inteface, how can i incorporate parceable in it. I have followed and searched about parceable, but it is only for object class. eg : How can I make my custom objects Parcelable? I want to pass my object list to another activity in android. code : public interface Projection { interface Job { @XBRead("./task") List<Task> getTasks(); @XBRead("./id") String getid(); @XBRead("./job_title") String getjob_title(); @XBRead("./job

Android Parcelable接口

蓝咒 提交于 2019-12-06 18:40:16
1、实现Parcelable就是为了进行序列化,那么,为什么要序列化? 1)永久性保存对象,保存对象的字节序列到本地文件中; 2)通过序列化对象在网络中传递对象; 3)通过序列化在进程间传递对象。 2、实现序列化的方法 Android中实现序列化有两个选择:一是实现Serializable接口(是JavaSE本身就支持的),一是实现Parcelable接口(是Android特有功能,效率比实现Serializable接口高效(高 10倍左右 ),可用于Intent数据传递,也可以用于进程间通信(IPC))。实现Serializable接口非常简单,声明一下就可以了,而实现Parcelable接口稍微复杂一些,但效率更高,推荐用这种方法提高性能。 注:Android中Intent传递对象有两种方法:一是Bundle.putSerializable(Key,Object),另一种是Bundle.putParcelable(Key,Object)。当然这些Object是有一定的条件的,前者是实现了Serializable接口,而后者是实现了Parcelable接口。 3、选择序列化方法的原则 1)在使用内存的时候,Parcelable比Serializable性能高,所以推荐使用Parcelable。 2)Serializable在序列化的时候会产生大量的临时变量,从而引起频繁的GC。

ArrayList cannot be cast to Parcelable

北战南征 提交于 2019-12-06 17:23:46
问题 I get following Errors: Key com..BookStatus expected Parcelable but value was a ArrayList ClassCastException: ArrayList cannot be cast to Parcelable -> and therafter: Unable to start Activity - NullPointerException the ArrayList do have values of BookStatus Objects (listToPass) Key com.example.books.BookStatus expected Parcelable but value was a java.util.ArrayList. The default value was returned Attempt to cast generated internal exception: java.lang.ClassCastException: java.util.ArrayList

Android Parcelable readStringArray bad array lengths [closed]

僤鯓⒐⒋嵵緔 提交于 2019-12-06 15:53:28
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . Can you tell me how to solve this? It throws a bad array length exception and after debugging, I found this method throws the Exception: --------------------------My Code----------------------------------- public class SingleModels implements Parcelable{ public String name; public String[] names ; @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) {

Overriding onSaveInstanceState

僤鯓⒐⒋嵵緔 提交于 2019-12-06 13:14:06
I'm trying to come to grips with the onSaveInstanceState method in class View (not the one in class Activity ). That method does return a Parcelable . I derived my own View from ViewGroup and overrode that method to save my own state. But when the state was to be saved I got an exception: java.lang.IllegalStateException: Derived class did not call super.onSaveInstanceState() That is true enough, but simply calling that method doesn't seem enough to me. So how should I do this? If the method would get passed a Parcel to write to, I could simply pass that same parcel to the super class, so

Android Parcel in ViewPager

冷暖自知 提交于 2019-12-06 12:41:47
I'm using ViewPager in my app and when I press home button during the interaction with ViewPager , the app crashes and I get this error : 3780-3780/? E/AndroidRuntime: FATAL EXCEPTION: main java.lang.RuntimeException: Parcel: unable to marshal value OrdinaryFragment{42000b70 #0 id=0x7f090005 android:switcher:2131296261:0} at android.os.Parcel.writeValue(Parcel.java:1235) at android.os.Parcel.writeList(Parcel.java:622) at android.os.Parcel.writeValue(Parcel.java:1195) at android.os.Parcel.writeMapInternal(Parcel.java:591) at android.os.Bundle.writeToParcel(Bundle.java:1619) at android.os.Parcel

Android implement Parcelable objects with hashmap that contains another hashmap

坚强是说给别人听的谎言 提交于 2019-12-06 09:22:46
This is an extension for Android implement Parcelable object which has hashmap but mine is a little different. I have these classes public class EventDetails implements Parcelable { Private String id; Private String eventName; Private Long eventUnixTime; Private HashMap <String, User> pickedUser = null; } and public class User implements Parcelable { private String email; private String userName; private String userPicture; private Boolean hasLoggedInWithPassword; private HashMap<String, Object> dateJoined = null; public User() { } public User(String email, String userName, String userPicture,