0

So I have defined a simple Integer Array in Kotlin (in activity 1)

 var arr = intArrayOf(1, 2, 3, 4, 5)

The following Toast allows me to see the values in the array (in activity 1) as [1,2,3,4,5]

 Toast.makeText(getApplicationContext(), "My Array = " + arr.contentToString(), Toast.LENGTH_LONG).show();

I then pass the array to a second activity using

  val intent = Intent(this, SecondActivity::class.java)
           
            intent.putExtra("key4", arr)

 startActivity(intent)

In activity 2 I use the following to get the array

  val newArr = intent ( "key4" )

Here I did try

 val newArr = intent .getSerializableExtra( "key4" )

But Android Studio Koala struck-out the .getSerializableExtra

Now I am trying to see the values using

Toast.makeText(getApplicationContext(), "My Array now = " + newArr.contentToString(), Toast.LENGTH_LONG).show();

But my output is

[!@c1b80a4] instead of [1,2,3,4,5]

Could someone please explain what I have done wrong ?

1
  • OK ! I have solved it ! I defined the Integer Array as an ArrayList and successfully passed that. Commented Aug 4, 2024 at 17:20

1 Answer 1

0

getSerializableExtra with single parameter is deprecated, which returns Serializable.

Instead use getSerializableExtra("key4", IntArray::class.java) that will return the value of an item previously added

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.