android - Pass the arraylist from one activity to another -
i trying pass complete arraylist 1 activity another.
i have tried way..
arraylist=new arraylist<hashmap<string,object>>(); intent i= new intent(listactivity.this,search.class); i.putextra("arraylist", arraylist); startactivity(i);
could me out @thanks
this not work because object
class in java not serializable. see this question explanation why.
the intent.putextra()
method requires type implements serializable interface, object not implement consequently not work. suggest rather having hashmap<string,object>
replace object more specific type implements serializable interface. see tutorial how this.
update
if data passing large there significant overhead associated serializing , deserializing. consequently might worth using static singleton class store arraylist. code sample below shows how implement this:
public class datastore { private static final datastore instance = new datastore (); private arraylist = new arraylist<hashmap<string,object>>(); //private constructor private datastore () {} //class accessible through method public static singleton getinstance() { return instance; } //accessors data private arraylist<hashmap<string,object>> getarraylist() { return arraylist; } private void setarraylist(arraylist<hashmap<string,object>> value) { arraylist = value; } }
for reference here tutorial on static singletons.
Well explained . There is also good java resource for beginners visit Java Tutorials
ReplyDelete