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
java android


source to share


No one has answered this question yet

Check out similar questions:

3606
Close / hide Android soft keyboard
3486
Why Java + =, - =, * =, / = do not require casting assignment operators?
3295
Why is the Android emulator so slow? How can we speed up the development of an Android emulator?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
2510
How to persist android activity state by persisting instance state?
2097
Is there a way to run Python on Android?
1858
"Debug certificate expired" error in Android Eclipse plugins
1844
What is "Context" on Android?
935
R cannot be resolved - Android error



All Articles
Loading...
X
Show
Funny
Dev
Pics