Passing String array between two class in android application

Solution 1:

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

Solution 2:

I suggest you to make get_array of set_array function in the class it is very simple I hope you already know this.

//Right in A... Class

String array[]=new String[5];
public void set_array(String arg[])
{
    array=arg;
}

public String[] get_array()
{
    return array;
}

//Right in B.. class for geting a string array

A mAObject=new A();
String classA_array=mAObject.get_array();

Solution 3:

If what you want to do is to pass data back and forth between activities, ie from Activity A, start Activity B and pass the string array, you can use the putStringArrayListExtra method when creating the intent:

http://developer.android.com/reference/android/content/Intent.html#putStringArrayListExtra%28java.lang.String,%20java.util.ArrayList%3Cjava.lang.String%3E%29

so in Activity A you would do something like:

Intent intentB = new Intent(this, ActivityB.class);
intentB.putStringArrayListExtra("name", <the array>);
this.startActivity(intentB)