The app I'm making retrieves between 1 and 2 dozen records from a table in a DB so that certain pieces of data can be used during the app (the table has 6 fields). It won't need to be stored permanently on the device. Is shared preferences used for something like this or should I be utilizing a bundle?
You can just query the db and get the data you want and store it in a normal fashion in variables.
SharedPreferences is mainly used when you want to retain data between different app executions.
Bundle is used when you want to safely transfer data between activities or between an activity and a fragment.
So unless you have some such requirements, you can just store them in normal variables.
If you want to access to same data from different activities and also if you are not going to store them permanently, you can use static variables in a class of your app. So;
// create static variable in a class
class SomeClassName {
public static ArrayList<MyObject> myObjects;
}
init the list when you get it from DB
SomeClassName.myObjects = GET_ITEMS_AND_REFERENCE_THEM;
then use it in another class like this
MyObject myObject = SomeClassName.myObjects.get(0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With