The problem as follows. Let us have 3 tabs with fragments:
- Tab 1 (Fragment A). Needs to send data to Tab 2.
- Tab 2 (Fragment B). Needs to receive data from Tab 1.
- Tab 3 (Fragment B). Already contains data.
As you see Tab 3 and Tab 2 contain the same Fragment but different instances.
How do I send data (not via arguments) to exactly Tab 2?
What I've tried:
- Set the unique ID for Fragment B via arguments when they were created.
- Register same
Local Broadcast Receiver
for both instances of Fragment B - Send data from Fragment A to Fragment B with its ID
- In Fragment B
onReceive()
check if recevied ID equals ID of Fragment
But unfortunately broadcast was sent to Tab 3 only.
EDIT: some more information.
Those tabs are hosted inside another fragment with ViewPager
. Thats due to combination of NavigationDrawer
which has fragment with ViewPager
and Tabs mentioned in question.