Android: how to restore an object, onResume, and save it onPause?

Make the class (MyClass) implement Serializable you can then save it as a file when the activity is destroyed, and restore it from file when it's resumed.

Make the class (MyClass) implement Serializable, you can then save it as a file when the activity is destroyed, and restore it from file when it's resumed public boolean ObjectToFile(String fileName, Object obj){ boolean success = false; FileOutputStream fos = null; ObjectOutputStream out = null; try{ File dir = GetAppDir(); if(dir! = null){ fos = new FileOutputStream(dir + "/" + fileName); out = new ObjectOutputStream(fos); out. WriteObject(obj); out.close(); success = true; } }catch(Exception e){} return success; } public Object FileToObject(String fileName){ Object obj = null; try{ File dir = GetAppDir(); if(dir!

= null){ File f = new File(dir, fileName); if(f.exists() && f.isFile()){ FileInputStream fis = null; ObjectInputStream in = null; fis = new FileInputStream(f); in = new ObjectInputStream(fis); obj = in.readObject(); in.close(); } } }catch(Exception e){} return obj; }.

Mmmm it won't work for me, because myclass its running thread. And when I press the back button doesn't kill the activity. – daniel fari Jun 21 at 16:42 PLEASE, do not use Serialization on Android, its incredible slow.

Please use Parcelables instead. – cyngus Jun 25 at 1:25.

Essentially you can't (and shouldn't) do what you're trying to do. If you have code that you want to continue to execute after the user ends a session*, your code should be running in association with a Service. The code should then be writing its work to persistent storage or your Service should allow for some binding interface for the newly created Activity to connect with the Thread.

*A session ends if a user backs our of your Activities. This is a different behavior than the user pressing the HOME key, which indicates that the user wants to resume what they were doing when they return to your application.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send