0

I want save instance on rotate. On simple textview i've done this but on arraylist i dont know how to do this. This is my problem: ArrayList cannot be converted to ArrayList

package com.example.view;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;

public class SecondActivity extends AppCompatActivity {

   Button button;
   ArrayList < ModelOceny > grades = new ArrayList < ModelOceny > ();

  // here is code to adding grades
   @Override
   protected void onSaveInstanceState(Bundle outState) {
       super.onSaveInstanceState(outState);
       outState.putParcelableArrayList("myArrayList", grades);
   }
   @Override
   protected void onRestoreInstanceState(Bundle savedInstanceState) {
       super.onRestoreInstanceState(savedInstanceState);
       grades =  (ArrayList<ModelOceny>) savedInstanceState.getParcelableArrayList("myArrayList");
   }

  //code to back to first activity & calculate avg

}
package com.example.view;

import android.os.Parcel;
import android.os.Parcelable;

public class ModelOceny implements Parcelable {
   // class structure and implementing Parcelable 
}
Rollermix
  • 13
  • 3
  • 1
    Does this answer your question? [How do you cast a List of supertypes to a List of subtypes?](https://stackoverflow.com/questions/933447/how-do-you-cast-a-list-of-supertypes-to-a-list-of-subtypes) – Regyn Jun 16 '21 at 12:22
  • Does this answer your question? [How to save custom ArrayList on Android screen rotate?](https://stackoverflow.com/questions/12503836/how-to-save-custom-arraylist-on-android-screen-rotate) – Gokul Nath KP Jun 16 '21 at 12:38
  • I tried to do like this https://stackoverflow.com/questions/31490657/how-to-use-onsaveinstancestate-method-with-arraylist/31490768 but im getting " incompatible types: ArrayList cannot be converted to ArrayList" – Rollermix Jun 16 '21 at 12:38

0 Answers0