Reputation: 4001
History In my project I have about 30 different screens, to acquire data. Now what usually I have to pass values from one screen to another. ( Like UserID, StoreID, City, etc )
What I currently do to pass values. I keep doing for 30 screens.
//Sender Activity
String strValue = "xyz";
Intent i = new Intent(this, ToClass.class);
i.putExtra("strValue", strValue);
startActivity(i);
//Receiving Activity
Intent intent = getIntent();
String strValue= intent.getExtras().getString("strValue");
Now my technical question is
a) The value in still alive (or uses memory) in the sender Activity. So how to I clear when moving to the next Activity?
b) Should it be better that I save strValue
value in DB
and access value from DB
whenever I need? Hence saving my memory.
c) Is this the best approach in Android. What I'm currently using.
Upvotes: 0
Views: 61
Reputation: 1588
a) leave the clearing of memory/data to GC it will take care of unused data in your memory.
b) if it is just a single value you don't want to put it in the DB
simply because it will use a memory
too and it will take much longer(in terms of ms
i think / overhead) rather than passing it as a bundle or in sharedpreference
c) if you want your strValue
to be alive only when the app is alive. that would be your approach. and if you want the strValue
to be in the memory i assume it is only 1 value you could use sharedpreference. and if you have so much data that you need to put in memory it is the time to use sqlite.
Upvotes: 1