androidparcelableandroid-savedstate

Error while saving ArrayList<String> in saved instance


Actually, I want to save my LinkedList in the saved instance so when a user opens the app again he can access the content already stored in the LinkedList. I know we need to convert the LinkedList into ArrayList in order to store it. While saving the ArrayList it gives me an error

wrong 2nd argument type in putParcelableArrayList(). Found 'java.util.ArrayList<java.lang.String>', required java.util.ArrayList<?extends android.os.Parcelable>.

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    ArrayList<String> arrayList = new ArrayList<String>(FavoriteQuotes);
    savedInstanceState.putParcelableArrayList("quotes",arrayList);
}

I know there are solutions available but it didn't seem to help me. Thanks.


Solution

  • You need to do like this

    ArrayList<String> arrayList = new ArrayList<String>(FavoriteQuotes);
    savedInstanceState.putStringArrayList("key",arrayList );