Issue
This is how I send an ArrayList:
val extras = Bundle()
val i = Intent(context, GalleryShow::class.java)
i.putExtra("list", ArrayList(memes))
(context as Activity).startActivityForResult(i, 777)
and receive it in Activity B:
intent.getParcelableArrayListExtra<Memes>("list") as ArrayList<Memes>
then after modifying it I set the intent that suppose to go back to Activity A:
private lateinit var finishIntent: Intent
finishIntent = Intent()
finishIntent.putExtra("list", ArrayList(modifiedMemes))
setResult(RESULT_OK, finishIntent)
and try to receive it in A:
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, intent)
if(requestCode == 777 && resultCode == RESULT_OK && data != null) {
if(data.hasExtra("list")) {
val updatedMemes = intent.getParcelableArrayListExtra<Memes>("list") as ArrayList<Memes>
}
}
}
so I set it exactly the same way for sending and recieving from a to b but I get the error:
kotlin.TypeCastException: null cannot be cast to non-null
on
val updatedMemes = intent.getParcelableArrayListExtra<Memes>("list") as ArrayList<Memes>
What is wrong here? Does google actually care that android is a giant disfunctional pile of dog crap?
Solution
You're reading from the wrong intent - you're using intent.getParcelableArrayListExtra<Memes>("list") as ArrayList<Memes>
, referring to the intent
property of your Activity and not the data
Intent that you received from onActivityResult()
:
val updatedMemes = data.getParcelableArrayListExtra<Memes>("list") as ArrayList<Memes>
Answered By - ianhanniballake
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.