Derek
Derek

Reputation: 63

Retrieving passed String Array elements - Android

I believe I am passing a String array from Class A to Class B correctly, however I am having a bit of trouble accessing each element individually. Here is a general view of my code.

String[] inputArr = new String[4];
//CLASS A=====================================          
inputArr[0] = zero;
inputArr[1] = one;
inputArr[2] = two;
inputArr[3] = three;

Bundle bundle = new Bundle();
bundle.putStringArray("input",inputArr);

//CLASSB==================================================
Bundle bundle = this.getIntent().getExtras();
String[] myStrings = new String[4];
myStrings = bundle.getStringArray("input");

So if this is correctly getting passed, then how would I go about assigning indivdual strings in Class B to the elements in the passed array? I have tried:

String aStr = myStrings[0];

However, this is showing the error message - "syntax error on token ";", Expression expected after this token." Is this the wrong method to use in this situation? If so, what should I be using? Thank you for your help in advance.

Upvotes: 1

Views: 676

Answers (2)

Arpit Garg
Arpit Garg

Reputation: 8546

Incase of Class A

i.putExtra("input",inputArr); 

In case of Class B

Bundle extras = getIntent().getExtras();
int arrayB = extras.getStringArray("numbers"); 

Upvotes: 1

Michael D. Irizarry
Michael D. Irizarry

Reputation: 6302

Try

String[] myStrings = getIntent().getStringArray("input");

Upvotes: 0

Related Questions