Android: NonConfigurationInstances cannot be added
I am trying to store the Radio array (a class I created) in the onRetainCustomNonConfigurationInstance method, but then when I try to cast it back with a cast for getLastNonConfigurationInstance I get this error:
java.lang.ClassCastException: android.support.v4.app.FragmentActivity $ NonConfigurationInstances cannot be passed to me .android .... lib.Radio []
Here is my code:
public void loadFeed() {
@SuppressWarnings("deprecation")
final Object data = getLastNonConfigurationInstance();
// the activity is starting for the first time
// read the json response and populate the radio stream list
if(data == null) {
//test
Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_SHORT).show();
populateListFromJson();
} else {
//test
Toast.makeText(getApplicationContext(), "2", Toast.LENGTH_SHORT).show();
// The activity was destroyed/created automatically, populate the radio stream
// list with the info load by the previous activity
final Radio[] radios = (Radio[]) data;
for(Radio radio : radios) {
radiosList.add(radio);
}
adapter.notifyDataSetChanged();
}
}
@Override
public Object onRetainCustomNonConfigurationInstance() {
// TODO Auto-generated method stub
return radios;
}
Can anyone help me?
+3
source to share
No one has answered this question yet
Check out similar questions: