How to save multiple values to a single variable through an activity.

I am creating an application in which I scan a number of bar codes and keep extracting their values and clubbing them in a single place. As simple as this sounds I have been unable to create either an array in which I keep storing new values or a string where I keep concatenating them.

Please comment in case someone needs more code or explanation, I understand the question might not be very rich in either.


 public class example 

    String val;
        public void onCreate(Bundle savedInstanceState)

              String list_id=ToolList3.ID; 
               String list_qty=ToolScanDet3.qty;

              // val is returned from the barcode scanning app.

              Log.d("Tools issued till yet...", val);

              /* Club all the tool IDs together and fire a single query to issue 
                                 them all against one name. */

              Intent i=new Intent(Issue.this,Issue1.class);

              //Issue1 again returns a pair of id and qty which needs to be saved along with the previous set of values.

I am basically having trouble trying to save the returned set of values along with the previous ones, the new ones that are returned wipe out the previous values. I tried putting them in an array too but that requires a counter which again defeats the purpose because the counter will be initialized to zero and start over again.


Unless the number of elements is known and constant, it is preferred to use ArrayList instead of array. In the case when you want to keep the data when the activity is destroyed caused by orientation change, you can save them in onSavedInstanceState :

protected void onSaveInstanceState(Bundle outState) {
    outState.putString("temp", tempString);

Then retrieve it back in onCreate:

protected void onCreate(Bundle savedInstanceState) {

    if(savedInstanceState != null) {
        your_arraylist = savedInstanceState.getString("temp");

EDIT: According to what you want, the Scan activity should not initialize any string. It should obtain the string value which is passed to it by the main instead:

    public class ScanActivity extends Activity {

    String tempString;

    protected void onCreate(Bundle savedInstanceState) {
    if(savedInstanceState == null) {
        tempString = getIntent().getStringExtra("temp");
    } else {
        // orientation change
        tempString = saveInstanceState.getString("temp");

Once you have finished the scan, do

Intent output = new Intent();
output.putExtra("temp", tempString);
setResult(RESULT_OK, output);

to send back the string to your Main activity.

Need Your Help

Parsing Binary Files in Client-side JS

javascript file-io binaryfiles

I'm wondering if there's any possible way of parsing a binary file in client-side Javascript. I would like to write a page that contains an HTML input form for a binary file ( a sound file is the end