0

I am trying to pass a single string array through about 3 classes to finally have the contents of the array[1] printed to a textview. I've been using intent to achieve this with my arraylists and it works fine. For some reason I'm unable to get it working with a measly string array. Here's what I'm doing.

Origin Activity of String Array:

private String [] decisionInput = new String[1];

 textData = etShouldI.getText().toString();

            if (!textData.matches("")){

            decisionInput[0] = (String.valueOf(textData));

                test.setText(decisionInput[0]); //TEST WORKS

               //CREATE BUNDLE
                Bundle bundle = new Bundle();
                bundle.putStringArray("decision", decisionInput);

                //SEND BUNDLE DATA
            Intent intent = new Intent(this,Pro.class);
                intent.putExtras(bundle);
                startActivity(intent);}

In my next Activity I've got the following, in order to receive the data, and send it off to the next Activity, and so on...

  String[] dPasser = new String[1];

@ONCREATE

//BUNDLE RECEIVER
   Bundle bundle = getIntent().getExtras();
    dPasser = bundle.getStringArray("decision");


    thisText.setText(String.valueOf(dPasser));  //TV currently returns null... 

@ONCLICK

//SEND DECISION DATA TO NEXT ACTIVITY
 Intent intent = new Intent(this, Next.class);
            Bundle b = new Bundle();
            b.putStringArray("decision", dPasser);
            intent.putExtras(b);

            startActivity(intent);

What the $%@& am I doing wrong guys?

1 Answer 1

1

You put the code below in a file named data, in your code you then use just it by calling data.array

public class data {
     public String[] array = new String[1];
}

But going with just passing through a String[] you shouldn't need bundle.

simply

intent.putExtra("stringArray".String[]);

and get it with

this.getIntent().getStringArrayExtra("stringArray")
Sign up to request clarification or add additional context in comments.

4 Comments

Could you give me a quick example of how to use public class data { public String[] array; } I'm not quite sure how I'd implement that.
Because my array receives data from an EditText, I'm not quite sure how to append data to the classed String array, sorry for the noobery.
Oh, sorry didn't notice that you wanted a one on it. Redid.
creating the class works, but appending data doesn't for me. I'll just have to use the other method you supplied. Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.