android - Saving state causes app to crash -


log saying activity cant paused, , number format exception, i'm trying save state of 2 edit texts hold numbers,but both can empty or 1 can empty

in activity there 2 edit texts user can either enter numbers manually , move next step or open calculator add numbers, , set total 1 of edit texts, want save state if needs fill both edit text using calculator, first number set still there when come second number.

i don't know deal this, here last bit of code tried.

protected void onsaveinstancestate(bundle outstate) {     super.onsaveinstancestate(outstate);      double length =double.parsedouble(edtnumber1.gettext().tostring());     double height = double.parsedouble(edtnumber2.gettext().tostring());      outstate.putdouble("length", length);     outstate.putdouble("height", height); } 

and in oncreate

if (savedinstancestate != null) {     double hght = savedinstancestate.getdouble("length");     double lnth = savedinstancestate.getdouble("length");     if (savedinstancestate.containskey("length")); {         edtnumber1.settext(double.tostring(lnth));     }      if(savedinstancestate.containskey("height")); {         edtnumber2.settext(double.tostring(hght));      } } 

try call super.onsaveinstancestate(outstate); @ end of method , make sure edittext contain numbers.

thus, change

double hght = savedinstancestate.getdouble("length");

by

double hght = savedinstancestate.getdouble("height");

and delete ; in if (savedinstancestate.containskey("length")); , if (savedinstancestate.containskey("height"));


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -