A simple solution on how to store the input value in SharedPreferences.
You can extend the MainActivity class or another class where you save the “value of what you want to keep”. Put this in the writer and reader classes:
public static final String GAME_PREFERENCES_LOGIN = "Login";
Here, InputClass is entered, and OutputClass is the output class, respectively.
// This is a storage, put this in a class which you can extend or in both classes: //(input and output) public static final String GAME_PREFERENCES_LOGIN = "Login"; // String from the text input (can be from anywhere) String login = inputLogin.getText().toString(); // then to add a value in InputCalss "SAVE", SharedPreferences example = getSharedPreferences(GAME_PREFERENCES_LOGIN, 0); Editor editor = example.edit(); editor.putString("value", login); editor.commit();
Now you can use it somewhere else, as in other classes. The OutputClass is called below.
SharedPreferences example = getSharedPreferences(GAME_PREFERENCES_LOGIN, 0); String userString = example.getString("value", "defValue");
Zly-zly
source share