Answer the question
In order to leave comments, you need to log in
Where to store temporary data while the application is running?
Hello.
Does android have something like a cookie/session like on the web?
It is necessary to store data throughout the entire operation of the application, so that every time they are needed not to pull the database ..
?
or store all the data in the object and transfer it when changing the activity?
Please advise, I will be very grateful
Answer the question
In order to leave comments, you need to log in
You can pass it to an Activity (using putExtra/Bundle), or you can use a "cookie type" (save on closing and restore on startup), these are Preferences or SharedPreferences.
If data is needed within one application run, then it must be passed from one part of your application to another.
Just build the class hierarchy correctly.
Try Dagger.
SharedPreferences you can play around with them, it’s convenient, you can store it in public access, you can keep it private, if information about a particular account, that is, AccountManager, this is when you go to the settings where accounts are hanging, here the account manager is responsible for it, but it’s better not to personal information there store, only general
You can use the singleton class in the Application object.
public class MyApplication extends Application {
private MyData myData;
public static MyApplication get(Context context) {
return (MyApplication) context.getApplicationContext();
}
public MyData getMyData() {
if (myData == null) {
myData = new MyData();
}
return myData;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question