I want to write a serializable object to file in internal memory. Then, I want to load that object back from that file later. How could I do this in Android?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First of all your object must implement
Serializable. Don’t forget to add aserialVersionUIDon the serializable class.Then if you don’t want to save specific field of the object mark it as
transient.Be sure all fields are serializable.
Next create a file in the internal memory and create an ObjectOutputStream to save your object. If you want to save in a specific folder you can create a path like this:
Then you can use that path to save your object:
Reading is similar: