1

I have an application with an FragmentActivity called MainActivity which holds two fragments, one menu fragment to the left and one content fragment to the right. On a large device both of these fragments are shown. On a small device only the menu fragment is shown and when the user presses an item in said menu the content fragment is displayed in a new Activity.

Lets say the user is currently using the application on his phone and only the menu is visible:

The ActionBar of MainActivity can be manipulated by user choices in the menu. When the user selects a specific menu item, a new Activity launches to display the content fragment. When this Activity pops up the ActionBar of this new Activity is a new ActionBar and therefore does not resemble the ActionBar of FragmentActivity (MainActivity).

I figured I could pass the ActionBar from MainActivity to the Activity which displays the content fragment through Intent extras, or making the ActionBar static and reference it like MainActivity.actionBar or similar, but I ran into problems very quickly :)

Any suggestions on how to solve this? Basically, what I want is to share a single ActionBar reference between all my activities.

Morten Salte
  • 505
  • 5
  • 21

1 Answers1

3

Maybe it's better to use fragments instead of activities. I mean show menu fragment, and when you need to show content fragment just put content fragment into the place (container) where was menu fragment. I think better/easier to organize fragment replace/change logics than trying to share actionbar between different activities.

ashakirov
  • 12,112
  • 6
  • 40
  • 40
  • You're probably right. I got my mind set on my approach from a tutorial I did but I agree your suggestion sounds better. Thanks :) – Morten Salte Jan 12 '13 at 15:16