Search code examples
androidparcelable

How to extract data from Parcelable Object in Android


I'm getting some hash code instead of real object in below code what could have been wrong.

    if(savedInstanceState != null)
    {
        posters = savedInstanceState.getParcelableArrayList(KEY_FOR);

        Toast.makeText(this,posters.toString(),Toast.LENGTH_LONG).show();

        MovieAdapter movieAdapter = new MovieAdapter(posters,this);
        mRecyclerView.setAdapter(mAdapter);

    }

Solution

  • According to official Android documentation return value of method getParcelableArrayList (String key) is ArrayList.

    In order to access items of this array, you need to loop through this list to get individual items.