Passing String Array Between Android Activities

Passing string array between android activities

Bundle b=new Bundle();
b.putStringArray(key, new String[]{value1, value2});
Intent i=new Intent(context, Class);
i.putExtras(b);


Hope this will help you.

In order to read:

Bundle b=this.getIntent().getExtras();
String[] array=b.getStringArray(key);

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

Passing string array to another activity

You have to do the following:

Intent i = new Intent("Activity")
i.putExtra(key, ArrayName)

Intent i = getIntent();
String[] array = i.getExtras().getString(keyname);

and that's it.

Android: Passing String Array over Multiple Activities

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

How to Pass Array to another activity?

Bundle b = new Bundle();
b.putStringArray(key, new String[]{value1, value2});
Intent i=new Intent(context, Class);
i.putExtras(b);

And for receiveing

Bundle b = this.getIntent().getExtras();
String[] array=b.getStringArray(key);

pass array of string between activities without using Intent or bundle

What is the problem to use array of string instead String?

Your scheme:

in the first activity i have declared a string

String str="abc"; // in activity1.java

and in the second activity am accessing it using this piece of code

String str2=activity1.str; // in activity2.java

Maybe just try it (in your case):

in the first activity i have declared a string

String[] arrayStr = {"abc", "xyz"}; // in activity1.java

and in the second activity am accessing it using this piece of code

String arrayStr2 = activity1.arrayStr; // in activity2.java



Related Topics



Leave a reply



Submit