M
M
MdaUZH2016-08-19 14:32:36
Android
MdaUZH, 2016-08-19 14:32:36

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

4 answer(s)
R
Rou1997, 2016-08-19
@Rou1997

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.

O
OnYourLips, 2016-08-19
@OnYourLips

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.

D
Dmitry, 2016-08-19
@Scotik

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

A
AlexeyVD, 2016-08-19
@AlexeyVD

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 question

Ask a Question

731 491 924 answers to any question