I send sendData
from StartActivity
to ResultActivity
.
val sendData = SendData(10, "xyz", "yss")
sendData.e = 933
sendData.f = "hello"
sendData.g = 39
// Log.d("A", "${sendData.toString}")
val intent = Intent(this@StartActivity, ResultActivity::class.java)
intent.putExtra(RESULT_DATA, sendData)
startActivity(intent)
sendData = intent.extras!!.getParcelable(RESULT_DATA)
// Log.d("B", "${sendData.toString}")
The model class looks like this.
@Parcelize
data class SendData(var a: Int, var b: String, var c: String) : Parcelable {
var e: Int? = null
var f: String? = null
var g: Int? = null
var isClicked = false
override fun toString(): String{
return JsonUtil.toJson(this) // custom util
}
}
But when I check the Log-A, Log-B.
// Log-A
{
"a": 10,
"b": "xyz",
"c": "yss",
"e": 933,
"f": "hello",
"g": 39,
"isClicked": false
}
// Log-B
{
"a": 10,
"b": "xyz",
"c": "yss",
"isClicked": false
}
So, the members which is defined as Nullable are null after being passed. What's the problem of this code?