Another alternative is to use your application to store these objects. A simple subclass application, make it single and declare it in your Manifest.xml
public class MyApplication extends Application { private static final MyApplication instance; public static MyApplication getInstace() { return instance; } public void onCreate() { instance = this; } private MyObject myObj; public MyObject getMyObject() { return this.myObj; } public void setMyObject(MyObject myObj) { this.myObj = myObj; } }
Then you can save it:
MyApplication.getInstance().setMyObject(anObject);
And restore it:
MyObject anObject = MyApplication.getInstance().getMyObject();
Remember, that:
- Declare the MyApplication class as Application in Manifest.xml
- If your process is killed or quits, your data will no longer be available.
source share