I am getting an unchecked cast warning and I am not sure if it is safe to suppress it.
I am putting an ArrayList<Fragment>
inside a Bundle
. This Bundle is then put in my Intent as following:
Intent mIntent = new Intent(getBaseContext(),MySecondActivity.class);
Bundle myBundle = new Bundle();
myBundle.putSerializable("fragmentList",ArrayList<Fragment>);
mIntent.putExtras(myBundle);
startActivity(mIntent);
Then on my new activity (MySecondActivity) I am retrieving this data with the following code:
(ArrayList<Fragment>) getIntent().getSerializableExtra("fragmentList")
My compiler gives me the following warning:
" Unchecked cast: 'java.io.Serializable' to 'java.util.ArrayList' "
Everything is working fine though, am I right to say I can safely suppress it?
Thank you!
Fragments are not Serializable, same for ArrayLists of Fragments. So, putSerializable
in this will not work, ever. even if they were serializable you would still need to use the method correctly. something like:
ArrayList<Fragment> fragmentArrayList = new ArrayList<Fragment>();
fragmentList.add(foo);
...
myBundle.putSerializable("fragmentList", fragmentArrayList); //not ArrayList<Fragment>
Instead try,
MySecondActivity
create these fragments you wanted to pass to it in the onCreate
MySecondActivity
in the bundle for that intent, but implement Parcelable
instead since it is a quicker/better than SerializableFor step two, here is a tutorial about making your data classes implement Parcelable
HTHs!!!