Skip to content Skip to sidebar Skip to footer

Android - Passing An Array Of Classes Between Activities

I have three different Classes or Activities in an array. Each Class represents a puzzle. I have a function that rearranges the array at the start of the app so that the user won't

Solution 1:

Since we're dealing with a Map, you should go with:

Object[] array = (Object[]) extras.get("classes"); // you cannot cast to Class[] !

and then:

Classa= (Class) array[0]; // and etc.

Solution 2:

You can look what the type of the second parameter of putExtra("classes", array) is, which turns out to be a Serializable.

Therefore you can get it back with getSerializable() and cast it to your Class array:

Class[] array = (Class[]) extras.getSerializable("classes");

Post a Comment for "Android - Passing An Array Of Classes Between Activities"