Passing a List through as a ParcelableArrayList

前端 未结 1 1470
灰色年华
灰色年华 2021-01-26 05:27

So hey guys, Im having some trouble with some code. Im implementing parcelables. Basically I have an List of items initiated globally as

private List

        
1条回答
  •  忘掉有多难
    2021-01-26 06:03

    Sadly Android doesn't "program to the interface". If the List is not an ArrayList then you'll have no choice but to create a new ArrayList. This isn't a big deal and can be done programmatically.

    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        ArrayList toSave = mMovieList instanceof ArrayList ?
            (ArrayList)mMovieList : new ArrayList(mMovieList);
        outState.putParcelableArrayList(MOVIE_KEY, toSave);
    }
    

    0 讨论(0)
提交回复
热议问题