Android: Do I have to send all the variables to retain the values before fragment transaction? -


suppose have 2 fragments , b. has 2 integer variables named data_1=2 , data_2=3. transaction fragment -> fragment b. note fragment b needs data_1 doesn't need data_2, so, send variable data_1 through bundle. so, when transaction fragment b -> fragment a, sending modified value of data_1, use new value of data_1 original value of data_2 = 3 retained ?

if not, how retain value?

there various ways of doing it, easiest way in opinion share data parent activity.

basically so:

class mainactivity extends activity {      public static int data_1 = 1, data_2 = 2;        //all other code goes here } 

then in child fragment set data go:

mainactivity.data_1 = 5; 

whereas read data call static value.

int current_data = mainactivity.data_1; 

if need instances of activity whatever reason can set getter , setter functions instance's (not static) variable.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -

Why does a .NET 4.0 program produce a system.unauthorizedAccess error on a Windows Server 2012 machine with .NET 4.5 installed? -