-1

I am trying to pass arrylist of NameValuePair one activity to another acivity,I searched so much for this ,i found similar questions But i am unable to get Answer,I tried but i am getting exception ,Please anybody tell me how to pass

    ArrayList<NameValuePair> namevlaList= new ArrayList<NameValuePair>();
    namevlaList.add(new BasicNameValuePair("formal_name",mLegalName));
    namevlaList.add(new BasicNameValuePair("device_phone_no",mPhno));
    namevlaList.add(new BasicNameValuePair("email",mEmail));
    namevlaList.add(new BasicNameValuePair("contact_name",mContactName));
    namevlaList.add(new            
    BasicNameValuePair("contact_number",mContactNumber));
    namevlaList.add(new BasicNameValuePair("password",mPwd));  
    Intent intent = new 
    Intent(this,Second.class);
    intent.putExtra("extra", namevlaList);
    startActivity(intent);
barq
  • 3,681
  • 4
  • 26
  • 39

2 Answers2

0

You can pass using Bundle

Intent intent = new Intent(this,Second.class);
Bundle extra = new Bundle();
extra.putSerializable("extra",  namevlaList.toArray());// cast to array and put
intent .putExtras(extra);
startActivity(intent);

and on Second Activity

Intent i = getIntent();
Bundle extras = i.getExtras();
List<NameValuePair> Namevaluepairvariable = new ArrayList<NameValuePair>();
Namevaluepairvariable =  (List<NameValuePair>) extras.getSerializable("extra");

use implements Serializable for your Second Activity

W I Z A R D
  • 1,224
  • 3
  • 17
  • 44
0

you can do like this, hope it helps

Intent intent = new Intent(this,Second.class);
intent.putExtra("namevlaList", namevlaList);
startActivity(intent);

in next activity use this

// initialize array list in onCreate
namevlaList= (ArrayList) getIntent().getExtra().get("namevlaList");

also see this link

this is because BasicNameValuePair is not serializable see this hope it helps

Community
  • 1
  • 1
Syed Raza Mehdi
  • 4,067
  • 1
  • 31
  • 47