android - OutputStreamWriter not saving data when activity stopped -


in app user goes different activities buy upgrades , want if close app on activity stuff saved.

this way of saving information:

public void onstop(){     super.onstop();     writecounttofile();     writesingletofile();     writeaddtofile(); }  public void writecounttofile() {     try {         outputstreamwriter outputstreamwriter = new outputstreamwriter(openfileoutput("countvalue.txt", context.mode_private));         outputstreamwriter.write(string.valueof(countervalue));         outputstreamwriter.close();     } catch (ioexception e) {         log.v("myactivity", e.tostring());     } }   private int readcountfromfile() {      string result = "";     int countervalue = 0;     try {          inputstream inputstream = openfileinput("countvalue.txt");          if (inputstream != null) {              inputstreamreader inputstreamreader = new inputstreamreader(inputstream);             bufferedreader bufferedreader = new bufferedreader(inputstreamreader);              string tempstring = "";             stringbuilder stringbuilder = new stringbuilder();              while ((tempstring = bufferedreader.readline()) != null) {                  stringbuilder.append(tempstring);              }              inputstream.close();              result = stringbuilder.tostring();             countervalue = integer.parseint(result);          }       } catch (filenotfoundexception e) {         log.v("myactivity", "file not found" + e.tostring());     } catch (ioexception e) {         e.printstacktrace();     } catch (numberformatexception e) {         //here catch , watch problem         log.e("myactivity", "cant parse string: " + result);     }     return countervalue; }  public void writeaddtofile() {     try {         outputstreamwriter outputstreamwriter = new outputstreamwriter(openfileoutput("addvalue.txt", context.mode_private));         outputstreamwriter.write(string.valueof(add));         outputstreamwriter.close();     } catch (ioexception e) {         log.v("myactivity", e.tostring());     } }   private int readaddfromfile() {      string result = "";     int add = 0;     try {          inputstream inputstream = openfileinput("addvalue.txt");          if (inputstream != null) {              inputstreamreader inputstreamreader = new inputstreamreader(inputstream);             bufferedreader bufferedreader = new bufferedreader(inputstreamreader);              string tempstring = "";             stringbuilder stringbuilder = new stringbuilder();              while ((tempstring = bufferedreader.readline()) != null) {                  stringbuilder.append(tempstring);              }              inputstream.close();              result = stringbuilder.tostring();             add = integer.parseint(result);          }       } catch (filenotfoundexception e) {         log.v("myactivity", "file not found" + e.tostring());     } catch (ioexception e) {         e.printstacktrace();     } catch (numberformatexception e) {         //here catch , watch problem         log.e("myactivity", "cant parse string: " + result);     }     return add; }  public void writesingletofile() {     try {         outputstreamwriter outputstreamwriter = new outputstreamwriter(openfileoutput("single.txt", context.mode_private));         outputstreamwriter.write(string.valueof(singleadd));         outputstreamwriter.close();     } catch (ioexception e) {         log.v("myactivity", e.tostring());     } }   private int readsinglefromfile() {      string result = "";     int single = 1;     try {          inputstream inputstream = openfileinput("single.txt");          if (inputstream != null) {              inputstreamreader inputstreamreader = new inputstreamreader(inputstream);             bufferedreader bufferedreader = new bufferedreader(inputstreamreader);              string tempstring = "";             stringbuilder stringbuilder = new stringbuilder();              while ((tempstring = bufferedreader.readline()) != null) {                  stringbuilder.append(tempstring);              }              inputstream.close();              result = stringbuilder.tostring();             single = integer.parseint(result);          }       } catch (filenotfoundexception e) {         log.v("myactivity", "file not found" + e.tostring());     } catch (ioexception e) {         e.printstacktrace();     } catch (numberformatexception e) {         //here catch , watch problem         log.e("myactivity", "cant parse string: " + result);     }     return single; } 

and when return app on main activity called read methods , have values of app equal upgrades, reason doesn't work. when close app main activity saves information fine, why copied methods main activity other activities. whats wrong?

please , thank you.

in experience onstop method not allow perform operations, solve call methods onpause method


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -