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,
putSerializablein this will not work, ever. even if they were serializable you would still need to use the method correctly. something like:Instead try,
MySecondActivitycreate these fragments you wanted to pass to it in theonCreateMySecondActivityin the bundle for that intent, but implementParcelableinstead since it is a quicker/better than SerializableFor step two, here is a tutorial about making your data classes implement
ParcelableHTHs!!!