johncarl81 / parceler

:package: Android Parcelables made easy through code generation.

Home Page:http://parceler.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to Marshall with Parceler

ScottAllsup opened this issue · comments

I have a Class(CheckWithQuestions.class)returned from Room, that contains two sub Classes (Check.class, Questions.class).

So the structure is:

@parcel
CheckWithQuestions {

Check check;
List questionList;

}

I have implemented @parcel on all three classes, as i pass these from Activity to activity.

As i would like to pass as many of these as the customer would like. I check the parcel size to ensure i dont cause TransactionTooLargeException.

I check this via a static method.

//1 Megabytes = 1048576 Bytes
private static final int maxBundleSize = 1048576;

/**
 * @param bundle Bundle size to be checked
 * @return True if bundle will cause a {@link TransactionTooLargeException}
 */
public static boolean BundleExtrasExceedingLimit(Bundle bundle){
    try {
        Parcel parcel = Parcel.obtain();
        parcel.writeValue(bundle);
        byte[] bytes = parcel.marshall();
        parcel.recycle();
        return bytes.length > maxBundleSize;

    }catch (Exception ignored){
        return false;
    }
}

However this is now unable to Marshall and grab the Byte size.
The try/catch isn't catching the exception either just straight crash.
Is there anyway to check the above while using Parcel?

Never mind it's not the above code thats failing, is a Parcel class within questionList. It only contains primitive fields.

Closing this. It was me being stupid.