I have a object, that has other objects inside. I need to pass that object to a FragmentDialog, so I made that object Serializable and it's working perfectly in my device.
public static SelectTeamDialog newInstance(Data data) {
SelectTeamDialog dialog = new SelectTeamDialog();
Bundle args = new Bundle();
args.putSerializable(ARG_PARAM1, data);
dialog.setArguments(args);
return dialog;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
data = (Data) getArguments().getSerializable(ARG_PARAM1);
}
}
The problem is that I'm seeing some NotSerializableException
reported in google developer console, so for some reason, in some devices, is giving NotSerializableException
.
It's important to say that Data object is very big, and has a lot of objects inside, with a lot of objects inside. And not all those objects are serializable, but I noticed that when you are passing the bundle to a Fragment or DialogFragment is not necessary that all the sub-objects contained in a serializable objects are serializable to pass that parent object with putSerializable in a bundle.
I know it because it's working in my device and 95% of the devices. But if I try to pass this serializable object with non serializable objects inside to an Activity with a bundle, it requires to make all the sub objects serializable too (I can't do it because then it gives outofmemory when serializing). Why is not necessary when passing it to a Fragment but it's necessary when working with Activities?
And why it's this giving me some exceptions reported in the developer console if it's working for me and for the 95% of the devices that are using this application?