This is a stylistic question more than an actual "how can this be done," but the basic situation is this: I have an Activity MyActivity
which contains a MapFragment
, as well as a List
of Renderers
which are my own class that takes care of displaying some data. The Renderers
also have ViewPagers
which get their content views from yet another class, let's call it ViewPagerTab
. Sometimes, something happens in some of these ViewPagerTabs
that necessitates the update of the map in the top level Activity
. There are, as I see it, a few approaches:
1) Both my Renderers
and my ViewPagerTabs
contain a reference to the context. If I cast the context as MyActivity
I can access its map parameter.
2) By using the reference to the context, I can call getSupportFragmentManager().findFragmentById(R.id.map)).getMap()
on it and get the map that way.
3) I can pass the map down from the Activity
to the Renderers
to the ViewPagerTabs
as they are created so the map is accessible in each as a class variable.
4) Use a BroadcastReceiver
in my Activity
and send a message to it when the map needs updating from my ViewPagerTab
.
Have I missed anything? What's the best/cleanest way of doing this?