0

Hello guys I have created a listview on second activity and I have three button on main activity .on click of each button it will display a listview with diffrent names in second activity. I dont how to pass a string array through intent and display in a listview.

MAIN ACTIVITY

String []str={"hello","world"};
String []str2={"display","text"};
String [] str3={"android","programming"};

Intet intent=new Intent  (this,Second activity. class);
intent.putExtra("stringA",how to pass the string array here)
startActivity  (intent);

2 Answers2

1
String []str={"hello","world"};
Bundle b = new Bundle();
b.putStringArray("key", str);
Intent i = new Intent(context, YourActivity.Class);
i.putExtras(b);

then to get from your second activity

Bundle data = this.getIntent().getExtras();
String[] array = data.getStringArray("key");
Masum
  • 4,879
  • 2
  • 23
  • 28
0

On MainActivity Button Click you call this

Bundle bundle=new Bundle();
bundle.putStringArray(key, new String[]{value1, value2});
Intent i=new Intent(ActivityA.this, ActivityB.Class);
i.putExtras(bundle);

to read in SecondActivity call this.

Bundle bundle=this.getIntent().getExtras();
String[] array=bundle.getStringArray(key);
susaine
  • 141
  • 1
  • 9