L
L
loly2016-05-23 07:15:07
Java
loly, 2016-05-23 07:15:07

How to store data that is needed everywhere and always on android?

Yes, we have many methods for storing information - from SharedPreferences to ExternalStorage.
Yes, we can drag data along with "intent.putExtra".
However, when using the first "yes", we will have to spend resources and time in each onCreate on constantly defining classes and information, and in the second, their definition is added to all this before creating an intent, as well as constant duplication (?) of this information (I’m not sure about the latter - I’m arguing purely logically, all previous activations and their data remain in the backStack).
This raises the question - how exactly should such data be stored?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rou1997, 2016-05-23
@Rou1997

A static container class, there can't be a faster and lighter option.
Calculate how many specific resources and time, most likely, will not be critical at all.

I
Ilya Pavlovsky, 2016-05-26
@TranE91

Singleton
Вы там посмотрите кучу реализаций, глянете что да как, лично я предпочитаю такую версию Singleton-а

class enum MySingleton{
 INSTANCE;
// дальше данные
}

Александр, 2016-06-28
@lomovskiy2

Создаёте статический класс - helper для работы с SharedPreferences, пишите нужные методы для put и get, а потом в нужно месте дергаете MySPHelper.putMyVariable(Context, Variable);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question