how to deserialize this type:
public Intent putExtra(String name, Serializable value)
example:
intent.putExtra("activityToPass", GoToThisActivity.class);
???
getIntent().getExtras.getSerializable("activityToPass");
how to do this please;
please help!!
If you want to pass a custom object from one activity to the other, first you must have your custom object's class to implement
java.io.Serializable
:Then you can add this myExtra to the intent with which you call your new
Activity
:Inside your
GoToThisActivity
class'onCreate
method you can extract this extra as:And now you have your custom object in your new activity.
Update 1: Passing a class to an other activity with
Intent
If you want to pass a
Class
instance to an intent:and to deserialize it in the other activity:
Update 2:
When deserializing an array of custom objects, you have to make sure, that the elements in that array implement the
Serializable
interface.To stay at your sample:
You put the extra in the
Intent
:And inside the other activity deserialize it:
You MUST cast the array as
Object[]
regardless to the original beingButtonPicks[]
.The elements inside the array have their proper type, so inside are the
members.
You need to cast them individually.