Is there a way I can put a List<Spanned> in a SaveInstanceState bundle?

252 views Asked by At

I am trying to store 2 String ArrayLists and 1 Spanned ArrayList in a SaveInstanceState in my android app. Is this possible? If so, can you provide an example?

ArrayListList<String> businessNames = new ArrayList<String>();
List<Spanned> businessInfo = new ArrayList<Spanned>();
ArrayList<String> businessCategories = new ArrayList<String>();


protected void onSaveInstanceState(Bundle bundle) {
    super.onSaveInstanceState(bundle);
    bundle.putStringArrayList("businessNames", businessNames);
    bundle.putStringArrayList("businessCategories", businessCategories);
    // ??????
    bundle.putParcelableArrayList("businessInfo", businessInfo); 
}
1

There are 1 answers

2
Zack On BEST ANSWER

Solved this myself. Here is the code below...

ArrayList<String> businessNames = new ArrayList<String>();
List<Spanned> businessInfo = new ArrayList<Spanned>();
ArrayList<String> businessCategories = new ArrayList<String>();


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    expListView = (ExpandableListView) findViewById(R.id.lvExp);
    String userChoice = (String) getIntent().getExtras().get("userChoice");

        if (savedInstanceState != null){
            businessInfo = (List<Spanned>) savedInstanceState.getSerializable("businessInfo");
            businessNames = savedInstanceState.getStringArrayList("businessNames");
            businessCategories = savedInstanceState.getStringArrayList("businessCategories");

            new DisplaySavedResults().execute();

        } else {
            new RetreiveSearchResults().execute(userChoice);
        }
}


protected void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    savedInstanceState.putStringArrayList("businessNames", businessNames);
    savedInstanceState.putStringArrayList("businessCategories", businessCategories);
    savedInstanceState.putSerializable("businessInfo", (Serializable) businessInfo);
}

The new asynctask DisplaySavedResults simply just does the UI changing in the onPostExecute. The doInBackground is left empty.