Reputation: 4692
my problem is putextra method with serializable object array. I mean if i try bottom code it throws Caused by: java.io.NotSerializableException:
Here 's the code :
class Example implements Serializable
{
private int ID; // It has getters and setters and also other variables.
}
Intent inte=new Intent(this,OTHERCLASS.class);
Example[] examples=new Example[]; // It's just an example.
Bundle bundle = new Bundle();
bundle.putSerializable("Details", examples);
inte.putExtras(bundle);
startActivity(inte);
Thanks.
Upvotes: 2
Views: 7443
Reputation: 12347
this is because you can't serialize a inner class without making its parent class serializable. Which in your case is your Activity. So simply create a new java file for your Example class
Upvotes: 4
Reputation: 11514
Although your class is serializable, an Array of items with your class ( Edit: Thanks @gomino for pointing out that this was wrong. I just assumed this was the reason for the problem without actually thinking about it.Example[]
) is not serializable.
Also, it would be more efficient to use a Parcelable instead. You can find a tutorial here.
Upvotes: 3