How to make a class with nested objects Parcelable

I finally figured out what to type into Google :), and found this Android, How to use readTypedList method correctly in a Parcelable class? The solution was to use read-/writeTypedList instead. I also initialize the arraylist to avoid any further NullPointerException. Class A public class A implements Parcelable { public String str; public ArrayList<B> list … Read more

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

The first error: ‘The Method Put Extra is Ambiguous for the type Intent’. The class Car is both Serializable and Parcelable, the compiler doesn’t know whether to use putExtra(Serializable s) or putExtra(Parcelable p) to handle your request. So you have to cast your Car to one of them when using Intent.putExtra(). Intent.putExtra(“car”, (Parcelable)myCarObject); Intent.putExtra(“car”, (Serializable)myCarObject); … Read more

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

There’s some rules for write and read parcelables. 1- Be careful about type mismatch. If you write int, don’t try to read long etc. 2- Be careful about order of writes and reads. Objects must be at the same sort order when reading and writing. Both of these can cause “Unmarshalling unknown type code”.

Android Unit Testing: Bundle/Parcelable

I’ve found this link showing how you can unit test a parcelable object: http://stuffikeepforgettinghowtodo.blogspot.nl/2009/02/unit-test-your-custom-parcelable.html You can actually skip the Bundle if you don’t really need to include it like zorch did his suggestion. You would then get something like this: public void testTestClassParcelable(){ TestClass test = new TestClass(); // Obtain a Parcel object and write … Read more

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

First create a helper class ParcelableUtil.java: public class ParcelableUtil { public static byte[] marshall(Parcelable parceable) { Parcel parcel = Parcel.obtain(); parceable.writeToParcel(parcel, 0); byte[] bytes = parcel.marshall(); parcel.recycle(); return bytes; } public static Parcel unmarshall(byte[] bytes) { Parcel parcel = Parcel.obtain(); parcel.unmarshall(bytes, 0, bytes.length); parcel.setDataPosition(0); // This is extremely important! return parcel; } public static <T> … Read more

Android getParcelableExtra deprecated

Here are two extension methods that I use for Bundle & Intent: inline fun <reified T : Parcelable> Intent.parcelable(key: String): T? = when { SDK_INT >= 33 -> getParcelableExtra(key, T::class.java) else -> @Suppress(“DEPRECATION”) getParcelableExtra(key) as? T } inline fun <reified T : Parcelable> Bundle.parcelable(key: String): T? = when { SDK_INT >= 33 -> getParcelable(key, T::class.java) … Read more

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

Between Activity: Worked for me ArrayList<Object> object = new ArrayList<Object>(); Intent intent = new Intent(Current.class, Transfer.class); Bundle args = new Bundle(); args.putSerializable(“ARRAYLIST”,(Serializable)object); intent.putExtra(“BUNDLE”,args); startActivity(intent); In the Transfer.class Intent intent = getIntent(); Bundle args = intent.getBundleExtra(“BUNDLE”); ArrayList<Object> object = (ArrayList<Object>) args.getSerializable(“ARRAYLIST”); Hope this help’s someone. Using Parcelable to pass data between Activity This usually works when … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)