0

Android アプリの SaveInstanceState に 2 つの String ArrayLists と 1 つの Spanned ArrayList を格納しようとしています。これは可能ですか?もしそうなら、例を挙げていただけますか?

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); 
}
4

1 に答える 1

-1

これを自分で解決しました。これが以下のコードです...

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);
}

新しい asynctaskDisplaySavedResultsは、 で UI の変更を行うだけonPostExecuteです。doInBackgroundは空のままです。

于 2013-12-31T15:27:57.973 に答える