Answer the question
In order to leave comments, you need to log in
Activities, Fragments, Particles...?
With the advent of fragments, it has become somewhat easier to separate the code.
But what if the fragment code grows into god-objects?
I solve the problem like this: I
group the views by functionality (Say, element selection and a button for creating a new one) and put them in a separate class (Conventionally calling it a particle), in which I resolve elements and do other dirty work.
But here the problem arises of forwarding callback calls from the hosting component: a fragment or an activity directly ( say , after creating a new element called startActivityForResult
, you can get the result only inonActivityResult
host component, and you have to forward the data to the child component).
How do you solve such a problem?
Answer the question
In order to leave comments, you need to log in
If I understand the problem correctly, then in this case, the Listener pattern is convenient for data transfer.
You just need to pay attention that in case of changing the position of the screen or other action leading to the re-initialization of the fragment, the listeners must be set again.
But, if the fragment exists in a single copy, the listener is defined as static and when the fragment is restarted, it does not fall off.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question