The content of the activity (not the MainActivity) is taken from the first fragment from SQLite via the Intent (there are no problems with this). In this, there is a button in the activation, by pressing which it is necessary to take one of the parameters that came into it through the Intent and transfer them to the second fragment. Both fragments have already been created via the FragmentManager in the MainActivity. It cannot be transmitted through Intent, it also does not come out through newInstance, since creates a fragment that is already there. Actually the question is - how to transfer the necessary parameters from the activation to the fragment, for example, as in my case the string?
- for example with the help of such a thing github.com/greenrobot/EventBus or such a square.imtqy.com/otto Just don’t get carried away with it and use it when you really can’t do without it, and then you can pile it up - andreich
- Thank. This, as I understand it, is stronie development. Are there any standard ways to do this? - Shura Balaganov
- standard methods - we assign tags to fragments. Find in the FragmentManager the desired fragment by tag. In the fragment itself, we make the method of passing the value. We call this method or implementation of the callback interface on the fragment found by the tag, depending on the tasks to be solved. - pavlofff
|
1 answer
I will write here in general terms how this can be done. We create the SomeInterface interface with one method that will accept the string, and make the fragment implement this interface.
When you need to transfer data from the activation to the fragment, take the current fragment (you can save it to a variable, but it’s better to get the fragmentManager by tag) and check if the fragment SomeInterface , if yes, you can safely cast and call the desired method.
|