Используя SharedPreferences, вы можете сделать это:
int answer_number = 4;
String answer = "the answer of the user";
//Your id is the identifier and location of your SharedPreferences because you can have
//multiple instances of SharedPrefernces.
String id = "quiz-application";
SharedPreferences sharedPref = getActivity().getSharedPreferences(id, Context.MODE_PRIVATE);
//The editor
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString(String.valueOf(answer_number), answer);
editor.apply();
Этим вы можете сохранить в своем файле "quiz_application" .sharedpreferences ваши ответы и позже получить к ним доступ, выполнив это:
SharedPreferences sharedPref = getActivity().getSharedPreferences(id, Context.MODE_PRIVATE);
String answer = sharedRef.getString("1", "no answer found");
//The 1 being the answer number while the second parameter being a fail-safe,
//if there isn't anything there it would return "no answer found".
Имейте в виду, что вам все еще нужны идентификатор и номер ответа, чтобы получить информацию.Номер ответа в этом случае прост, он может принимать только следующие значения: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.Вам нужно позаботиться об идентификаторе.