Java Code Examples for android.os.Parcel.dataSize()

The following are Jave code examples for showing how to use dataSize() of the android.os.Parcel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: garras   File: Bundler.java   View Source Code Vote up 5 votes
@NonNull
public Bundle end() {
    Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);
    int size = parcel.dataSize();
    Timber.e(String.valueOf(size));
    if (size > 500000) {
        bundle.clear();
    }
    return get();
}
 
Example 2
Project: toolargetool   File: TooLargeTool.java   View Source Code Vote up 5 votes
/**
 * Measure the size of a typed {@link Bundle} when written to a {@link Parcel}.
 *
 * @param bundle to measure
 * @return size when written to parcel in bytes
 */
public static int sizeAsParcel(@NonNull Bundle bundle) {
    Parcel parcel = Parcel.obtain();
    try {
        parcel.writeBundle(bundle);
        return parcel.dataSize();
    } finally {
        parcel.recycle();
    }
}
 
Example 3
Project: toolargetool   File: TooLargeTool.java   View Source Code Vote up 5 votes
/**
 * Measure the size of a {@link Parcelable} when written to a {@link Parcel}.
 *
 * @param parcelable to measure
 * @return size in parcel in bytes
 */
public static int sizeAsParcel(@NonNull Parcelable parcelable) {
    Parcel parcel = Parcel.obtain();
    try {
        parcel.writeParcelable(parcelable, 0);
        return parcel.dataSize();
    } finally {
        parcel.recycle();
    }
}
 
Example 4
Project: mvvm-template   File: Bundler.java   View Source Code Vote up 5 votes
@NonNull public Bundle end() {
    Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);
    int size = parcel.dataSize();
    Logger.e(size);
    if (size > 500000) {
        bundle.clear();
    }
    return get();
}
 
Example 5
Project: OpenHub   File: BundleHelper.java   View Source Code Vote up 5 votes
public Bundle build(){
    Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);
    if (parcel.dataSize() > 512 * 1024) {
        bundle.clear();
        throw new IllegalArgumentException("bundle data is too large, please reduce date size to avoid Exception");
    }
    return bundle;
}
 
Example 6
Project: garras   File: Bundler.java   View Source Code Vote up 4 votes
public static boolean isValidBundleSize(@NonNull Bundle bundle) {
    Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);
    return parcel.dataSize() < 500000;
}
 
Example 7
Project: mvvm-template   File: Bundler.java   View Source Code Vote up 4 votes
public static boolean isValidBundleSize(@NonNull Bundle bundle) {
    Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);
    return parcel.dataSize() < 500000;
}
 
Example 8
Project: chromium-for-android-56-debug-video   File: IntentUtils.java   View Source Code Vote up 3 votes
/**
 * Returns how large the Intent will be in Parcel form, which is helpful for gauging whether
 * Android will deliver the Intent instead of throwing a TransactionTooLargeException.
 *
 * @param intent Intent to get the size of.
 * @return Number of bytes required to parcel the Intent.
 */
public static int getParceledIntentSize(Intent intent) {
    Parcel parcel = Parcel.obtain();
    intent.writeToParcel(parcel, 0);
    return parcel.dataSize();
}