Object I/O Stream java android -


i want print object file when app onstop , read @ oncreate. when close app , reopen object not there. objects acts ok while navigating trough app, problem on restart.

the object instance ("tl") of tlist class - extends arraylist

read:

  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_my);      fileinputstream fis;     try {         fis = openfileinput("data_t");          objectinputstream ois = new objectinputstream(fis);         tl = (tlist)ois.readobject();          ois.close();      } catch (filenotfoundexception e) {         e.printstacktrace();     }catch(ioexception e){         e.printstacktrace();     } catch (classnotfoundexception e) {         e.printstacktrace();     } 

write:

    @override protected void onstop() {     super.onstop();      fileoutputstream fos;     try {         fos = openfileoutput("data_t", context.mode_private);          objectoutputstream oos = new objectoutputstream(fos);         oos.writeobject(tl);         oos.flush();         oos.close();     } catch (filenotfoundexception e) {         e.printstacktrace();     }catch(ioexception e){         e.printstacktrace();     } } 


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -