Passing String array between two class in android application

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");
}

Leave a Comment