arraylist - Referencing an ArrayListin another class? Java/Android -



arraylist - Referencing an ArrayListin another class? Java/Android -

i need help info management. can explain enough. create , instantiate arraylist in class a, want display info in class b. little trickier this, allow me explain steps.

i created setters , getters in class a

public static void setarray(arraylist<string> list) { classa.mlist = list; } public static arraylist<string> getarray() { homecoming mlist; }

while in class a, populate array 1 item, mlist.add("item"). have item in list (mlist), start new activity

intent intent = new intent(classa.this, classb.class); startactivity(intent);

i purposefully did not finish() activity. in class b, test if info persists printing out first item in array using getter method.

system.out.println("data persists? " + classa.getarray().get(0));

everything works fine point. finish() class b, brings me class a. added in onresume() class add together item list (mlist) , theni start sec activity (class b) again. utilize recursion check if have 2 items in arraylist, , there 1. checked in onresume if print out anything, , size of mlist 0. guess re-instantiated, , reset list?

how can maintain info in arraylist after leaving activity , returning back? want able add/update info arraylist every time homecoming class a

thank in advance

you should not utilize static methods share non-static info between activities. purpose please utilize intent passing temporary storage of data. illustration provided can refer putstringarraylistextra()

android arraylist

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -