SharedPref not keeping value for 1 array but working for another.
I am saving strings from Activty1 to a JsonArray for jsonArray_Score_Correct_book and jsonArray_Score_Correct_type
When getting these SharedPrefs from Activity 2, only the jsonArray_Score_Correct_type string values are retuned, the jsonArray_Score_Correct_book values return [] (empty).
Activity1
sharedPrefEditor = getSharedPreferences("SharedPrefFile", MODE_PRIVATE).edit();
sharedPref = getSharedPreferences("SharedPrefFile", MODE_PRIVATE);
jsonArray_Score_Correct_book.put(str_Book);
jsonArray_Score_Correct_type.put(str_Type);
sharedPrefEditor.putString("KEY_arrayListString_Score_Correct_book", jsonArray_Score_Correct_book.toString());
sharedPrefEditor.putString("KEY_arrayListString_Score_Correct_type", jsonArray_Score_Correct_type.toString());
sharedPrefEditor.apply();
Note: I am CHECKING and VERIFYING to see if these values are indeed saved and the log displays that both jsonArrays have string values as expected.
Log.d("LOG", "zzz_jsonArray_Score_Correct_book (Before Activity2): "+jsonArray_Score_Correct_book);
Log.d("LOG", "zzz_jsonArray_Score_Correct_type (Before Activity2): "+jsonArray_Score_Correct_type);
Then I call Activity2.
intent = new Intent(getApplicationContext(), Activity2.class);
startActivity(intent);
Activty2
sharedPrefEditor = getSharedPreferences("SharedPrefFile", MODE_PRIVATE).edit();
sharedPref = getSharedPreferences("SharedPrefFile", MODE_PRIVATE);
try {
jsonArray_Score_Correct_book = new JSONArray(sharedPref.getString("KEY_arrayListString_Score_Correct_book", "[]"));
jsonArray_Score_Correct_type = new JSONArray(sharedPref.getString("KEY_arrayListString_Score_InCorrect_type", "[]"));
Log.d("LOG", "zzz_jsonArray_Score_Correct_book (On Activity2): "+jsonArray_Score_Correct_book);
Log.d("LOG", "zzz_jsonArray_Score_Correct_type (On Activity2): "+jsonArray_Score_Correct_type);
Form Activity 2, only jsonArray_Score_Correct_type returns the correct values, however jsonArray_Score_Correct_book is empty.
Additional Information
I tried the following:
this.MODE_PRIVATE
getApplicationContext().MODE_PRIVATE
Also tried to get the values from Activity1 (after app stop and start), this also has the same behaviour as Activity 2 (only getting values for jsonArray_Score_Correct_type
Both array values are preserved correctly while in Activity 1 (after checking in different places, including putting logs in Opening and Closing navigation drawer, the arrays have strings as expected, the only issue is moving to a different activity (or restarting app), only jsonArray_Score_Correct_type is always stored not jsonArray_Score_Correct_book, these 2 arrays follow the same process throughout the app.