parcel

How to use writeStringArray() and readStringArray() in a Parcel

杀马特。学长 韩版系。学妹 提交于 2019-12-08 15:27:04
问题 I recently came across a very stupid (at least from my point of view) implementation inside Androids Parcel class. Suppose I have a simple class like this class Foo implements Parcelable{ private String[] bars; //other members public in describeContents(){ return 0; } public void writeToParcel(Parcel dest, int flags){ dest.writeStringArray(bars); //parcel others } private Foo(Parcel source){ source.readStringArray(bars); //unparcel other members } public static final Parcelable.Creator<Foo>

Using an ArrayList<String> with a class that extends Parcelable

我与影子孤独终老i 提交于 2019-12-08 08:32:47
问题 I'm having trouble with reading an ArrayList of Strings with a class that implements Parcelable. I want to send 3 ArrayLists of Strings to a Fragment. Another thing I don't understand is how I'd use this class to actually send this data to a Fragment (I read somewhere else that you can use your own parcelable class to do this, but I don't know exactly how). Here is the relevant code, I'll put comments in the places I think I need help. package com.tsjd.HotMeals; import java.util.ArrayList;

How to marshal/unmarshal ContentValues to insert generic type into ContentProvider?

大城市里の小女人 提交于 2019-12-07 12:12:17
问题 I want to put a generic POJO into ContentValues and unmarshall it within the ContentProvider. I've been wracking my tiny brain re: Parcelables, ContentValues, and inserting into SQLite Regarding: http://njzk2.wordpress.com/2013/05/31/map-to-contentvalues-abusing-parcelable/ How to write a common code for inserting data in android's Sqlite I've been trying to insert a android.location.Location into SQLite via ContentProvider: Location loc = mLocationClient.getLastLocation(); myParcel = android

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

How to marshal/unmarshal ContentValues to insert generic type into ContentProvider?

半腔热情 提交于 2019-12-05 19:00:21
I want to put a generic POJO into ContentValues and unmarshall it within the ContentProvider. I've been wracking my tiny brain re: Parcelables, ContentValues, and inserting into SQLite Regarding: http://njzk2.wordpress.com/2013/05/31/map-to-contentvalues-abusing-parcelable/ How to write a common code for inserting data in android's Sqlite I've been trying to insert a android.location.Location into SQLite via ContentProvider: Location loc = mLocationClient.getLastLocation(); myParcel = android.os.Parcel.obtain(); loc.writeToParcel(myParcel, 0); ContentValues values = ContentValues.CREATOR

Can Nulls be passed to parcel?

谁说胖子不能爱 提交于 2019-12-05 12:03:59
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? Richard Le Mesurier Yes, you can pass a null to the Parcel.writeString(String) method. When you read it out again with Parcel.readString() , you will get a null

What is the use of flags in Parcelable?

一笑奈何 提交于 2019-12-05 00:20:19
I have been writing Parcelable s to Parcel without any focus on flags field, which is a parameter in the method signature and it has worked fine but I have run into an implementation where I can no longer ignore them: public static <K extends Parcelable, V extends Parcelable> void write(Parcel dest, Map<K, V> map, int flags) { if (map == null) { dest.writeInt(-1); } else { Set<Map.Entry<K, V>> entrySet = map.entrySet(); dest.writeInt(entrySet.size()); for (Map.Entry<K, V> entry : entrySet) { dest.writeParcelable(entry.getKey(), flags); dest.writeParcelable(entry.getValue(), flags); } } } This

NullPointerException (etc) from Parcel.readException

北城余情 提交于 2019-12-04 20:11:20
问题 Exceptions that look like this are confusing: FATAL EXCEPTION: main java.lang.NullPointerException at android.os.Parcel.readException(Parcel.java:1437) at android.os.Parcel.readException(Parcel.java:1385) at com.yourpackage.ipc.IYourClass$Stub$Proxy.yourMethod(IYourClass.java:488) at com.yourpackage.ipc.YourClassShim.yourMethod(YourClassShim.java:269) I found a bunch of related questions for this, but none with the answer to "how do you debug this". So I'm making this Question/Answer. By

How to read and write Enum into parcel on Android?

夙愿已清 提交于 2019-12-04 08:02:02
问题 Here is my model class: public enum Action { RETRY, SETTINGS } private int imageId; private String description; private String actionName; private Action action; public NetworkError(int imageId, String description, String actionName, Action action ) { this.imageId = imageId; this.description = description; this.actionName = actionName; this.action = action; } public int getImageId() { return imageId; } public void setImageId(int imageId) { this.imageId = imageId; } public String

Shared memory region in NDK

喜欢而已 提交于 2019-12-01 12:55:24
I want to have a shared memory block (an ashmem region) that's mapped and accessed from native code. I also want this block to be used by several applications. I also want it to work on SDK level 7 (Android 2.1) There are two routes. I can create an ashmem region in native code; but then the question is - how do I pass an integer file descriptor to another process? You can marshal FileDescriptor objects via a Parcel , but there's no way to construct one around a raw FD. There's also ParcelFileDescriptor which supports constructing around and retrieving integer FD's, but the relevant methods