android - How to save multiple values to a single variable through an activity. -
i creating application in scan number of bar codes , keep extracting values , clubbing them in single place. simple sounds have been unable create either array in keep storing new values or string keep concatenating them.
please comment in case needs more code or explanation, understand question might not rich in either.
edit :
public class example { string val; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); try { string list_id=toollist3.id; string list_qty=toolscandet3.qty; // val returned barcode scanning app. val=val+issue_id+"~"+issue_qty+";"; log.d("tools issued till yet...", val); /* club tool ids , fire single query issue them against 1 name. */ intent i=new intent(issue.this,issue1.class); startactivity(i); //issue1 again returns pair of id , qty needs saved along previous set of values. }
i having trouble trying save returned set of values along previous ones, new ones returned wipe out previous values. tried putting them in array requires counter again defeats purpose because counter initialized 0 , start on again.
unless number of elements known , constant, preferred use arraylist instead of array. in case when want keep data when activity destroyed caused orientation change, can save them in onsavedinstancestate :
@override protected void onsaveinstancestate(bundle outstate) { super.onsaveinstancestate(outstate); outstate.putstring("temp", tempstring); }
then retrieve in oncreate:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); if(savedinstancestate != null) { your_arraylist = savedinstancestate.getstring("temp"); }
edit: according want, scan activity should not initialize string. should obtain string value passed main instead:
public class scanactivity extends activity { string tempstring; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); if(savedinstancestate == null) { tempstring = getintent().getstringextra("temp"); } else { // orientation change tempstring = saveinstancestate.getstring("temp"); } }
once have finished scan, do
intent output = new intent(); output.putextra("temp", tempstring); setresult(result_ok, output); finish();
to send string main activity.
Comments
Post a Comment