Task: In the first activity of Activity1, we create an instance of the VeryFatClass class:

VeryFatClass obj = new VeryFatClass ();

We carry out the necessary actions with him, and we want to transfer this particular object to Activity2 .

Problem: The fields of the VeryFatClass class are for the most part other objects in which fields are also objects (and in some of them fields are also objects).

How to organize control over the VeryFatClass object from more than 2 activities? my current solution is, I use a static field and a singleton pattern, but it seems to me that it is not quite right, because I have to hope that the cleaner will not demolish the instance I created in the first activity. Is there a way to protect yourself from this? I read about Parcelable , but as I understand it, I would have to do every field in which there is an object to do as Parcelable ?

  • Transferring objects between activations is best and easiest through EventBus or analogs. Parcelable Yes, you need to expand the object into primitive types. - pavlofff
  • It would seem such a simple task, and requires the study of libraries or, worse, writing code in the amount of 30% of the class size just to simply transfer this object to another activity. P - rationalism (no) - torin.dmitry
  • The problem is not in the platform, but in your architecture. Use the model layer to store the object and take the same object from the model to the second Activity . The Parcelable may not work on Android Nougat due to the transaction size limit ( developer.android.com/reference/android/os/… ) + at any time the system can kill the application process and the object is lost. - EgorD

0