shrutipawar111
shrutipawar111

Reputation: 111

Pass array of string to next activity on button click in Android

friends.I am new in android developement plz help me. I want to pass my array arrayItemName of string to next activity and display it on next activity on button click.

@Override
public void onClick(View v)
{
    // TODO Auto-generated method stub
  Intent intent = new Intent(MakeOrder.this,ConfirmOrder.class);
  String []arrayItemName=itemName.split("\\,");
  for(int i=0;i<arrayItemName.length;i++)
  {
   intent.putExtra("My_Array_ItemName",arrayItemName[i].toString());
  }
  startActivity(intent);
}

Upvotes: 0

Views: 882

Answers (3)

Android_coder
Android_coder

Reputation: 9993

Try this:

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:

if you nee to display the values after button click. you put the below code into onclick method

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

Upvotes: 0

ogzd
ogzd

Reputation: 5692

Try this:

 intent.putExtra("My_Array_ItemName", arrayItemName);
 startActivity(intent);

 ....

 Bundle extras = getIntent().getExtras();
 String[] arr = extras.getStringArray("My_Array_ItemName");

Upvotes: 0

Paresh Mayani
Paresh Mayani

Reputation: 128428

Try:

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

And on the receiver side:

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

Upvotes: 3

Related Questions