Saving data between actions using an external class

I am developing an application that should share lines between actions. I am trying to force individual actions to call an open class using set and get methods. Calling part of the methods works, and I manage to get an answer, although the set value must be remembered with the help of the set and get class. Here's a link to my set and class, it's pretty simple: http://pastebin.com/0WabNKz3

Now my question is: how to create a set and get a class to remember my values ​​between sessions? Feel free to ask questions if you do not understand anything.

Thanks!

+4
source share
3 answers

As a result, I created an invisible EditTextPreference, which now stores the data that I want to save, because it can be easily shared.

+1
source

You need to use SharedPreferences . To save data even after closing the application, and you can access it from anywhere:

 public void savePrefrences(String key, String value) { SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), 0); prefs.edit().putString(key, value).commit(); } public String getPrefrences(String key) { SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), 0); return prefs.getString(key, ""); } 

Maintain your advantage whenever and wherever you want, and get it whenever you want.

The value will not be deleted when the application is closed.

+1
source

When you talk about saving between sessions, do you mean that the application is paused or completely closed?

A good resource for the life cycle and data storage in sessions is: //developer.android.com/training/basics/activity-lifecycle/index.html

0
source

Source: https://habr.com/ru/post/1437640/


All Articles