0

hi i would like to send string arraylist values from one class another class.i tried using bundle concept but in second class in arraylist showing null value.plaese any one suggest me wherre did mistake..

  Activity1.class:
 public static ArrayList<String> customers = new ArrayList<String>();
        customers.add("radha");
        customers.add("aswini");
           Intent i=new Intent(Activity1 .this,Activity2.class);
         i.putExtra("customers1", customers);
        Log.i("arrayvalues1",""+ customers);
        startActivity(i);

     Activity2.class:
     String[] mystringArray = getIntent().getStringArrayExtra("customers1");
    Log.i("arrayvalues2",""+ mystringArray);

4 Answers 4

2
ArrayList<String> mystringArray = getintent().getStringArrayListExtra("customers1");
Sign up to request clarification or add additional context in comments.

Comments

0

when the arraylist is public static, you can directly access it using classname.arraylist na.

Activity1.cutomers

4 Comments

read above two answer..that will be helpful..Dont use static cause that's not reliable,creates memory leaks..also see stackoverflow.com/questions/2475978/…
hmm...yeah, otherwise its too obvious :P
yes it it obvious :)..that developer use it..but going through documentation and good blogs..you will find that Static can make how much trouble for you..
hi,sory.in Avtivity2 i use Activity1.customers=customers1; but in customers1 null value is there.
0

If you create a public static variable, you can access it in a static way:

In Activity2.class:

Activity1.customers;

2 Comments

sory.but Activity1.customers=customers1; i use like this,but in customers1 null value is there
Sorry but that doesn't make much sense.
0

For Activity 1:

 ArrayList<String> Customers = new ArrayList<String>();
 Intent i=new Intent(Activity1 .this,Activity2.class);
 i.putStringArrayListExtra("customers1",(ArrayList<String>) Customers);         
 startActivity(i);

For Activity 2:

 ArrayList<String> Customers = new ArrayList<String>();
 Bundle extra=getIntent().getExtras();
    if(extra!=null){
        Customers =extra.getStringArrayList("customers1");  
    }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.