ParcelableHeapAnalysis.kt
TLDR
The ParcelableHeapAnalysis.kt
file contains a class ParcelableHeapAnalysis
that implements the Parcelable
interface. This class wraps an instance of the HeapAnalysis
class and provides methods to write and read instances of ParcelableHeapAnalysis
to and from a Parcel
.
Classes
ParcelableHeapAnalysis
This class implements the Parcelable
interface and wraps an instance of the HeapAnalysis
class. It provides methods to write and read instances of ParcelableHeapAnalysis
to and from a Parcel
.
Companion Object
The companion object of ParcelableHeapAnalysis
provides the following methods:
-
createFromParcel(source: Parcel)
: This method is used by theCREATOR
field to create an instance ofParcelableHeapAnalysis
from aParcel
. -
newArray(size: Int)
: This method is used by theCREATOR
field to create an array ofParcelableHeapAnalysis
with the specified size. -
HeapAnalysis.asParcelable()
: This extension function converts an instance ofHeapAnalysis
to an instance ofParcelableHeapAnalysis
.
package org.leakcanary.internal
import android.os.Parcel
import android.os.Parcelable
import shark.HeapAnalysis
class ParcelableHeapAnalysis(val wrapped: HeapAnalysis) : Parcelable {
private constructor(source: Parcel) : this(source.readSerializable() as HeapAnalysis)
override fun writeToParcel(dest: Parcel, flags: Int) {
dest.writeSerializable(wrapped)
}
override fun describeContents() = 0
companion object {
@Suppress("UNCHECKED_CAST")
@JvmField val CREATOR = object : Parcelable.Creator<ParcelableHeapAnalysis> {
override fun createFromParcel(source: Parcel): ParcelableHeapAnalysis {
return ParcelableHeapAnalysis(source)
}
override fun newArray(size: Int): Array<ParcelableHeapAnalysis?> {
return arrayOfNulls(size)
}
}
fun HeapAnalysis.asParcelable(): ParcelableHeapAnalysis = ParcelableHeapAnalysis(this)
}
}