Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing String array between two class in android application

Tags:

android

I am new to Android. How should I pass a String array between two classes?

I tried Intent, by sharing String array between the class, but I get only one String, the rest of the Strings will not displayed.

Can I use a Bundle? Is there some better way to pass a String array?

like image 766
RAAAAM Avatar asked Mar 07 '11 07:03

RAAAAM


1 Answers

If you are trying to send a String-array from one Activity to another this can be done in the Intent.

In ClassA:

Intent intent = new Intent(this, ClassB);
String[] myStrings = new String[] {"test", "test2"};
intent.putExtra("strings", myStrings);
startActivity(intent);

In ClassB:

public void onCreate() {
  Intent intent = getIntent();
  String[] myStrings = intent.getStringArrayExtra("strings");
}
like image 98
Eric Nordvik Avatar answered Oct 10 '22 04:10

Eric Nordvik