SerializableIntent.kt
TLDR
This file contains the definition of the SerializableIntent
class, which is used to wrap an Intent
and serialize it as its URI string.
Classes
SerializableIntent
This class wraps an Intent
object and serializes it as its URI string. It implements the Serializable
interface to enable serialization. The class has the following properties and methods:
-
uri
: This property stores the URI string representation of the wrappedIntent
. -
_intent
: This property is transient and holds the reference to the originalIntent
object. It is not serialized. -
intent
: This property returns the deserializedIntent
object. If the_intent
property is null, it parses theuri
string and initializes_intent
before returning it.
package leakcanary.internal
import android.content.Intent
import java.io.Serializable
/**
* Wraps an Intent to serialize it as its URI string.
*/
internal class SerializableIntent(intent: Intent) : Serializable {
private val uri = intent.toUri(0)
// Intent is not Serializable
@Transient
private var _intent: Intent? = intent
val intent: Intent
get() = _intent.run {
this ?: Intent.parseUri(uri, 0)
.apply { _intent = this }
}
}