Search code examples
design-patternsandroid-actionbarandroid-searchmanagerandroid-search

Action Bar on Android is a Singleton?


When we are working with the Search Widget in Android and create multiple times, maybe, search widgets in order to know what was written... does the action bar works like a layer? Is ever the same action bar no matter in which activity I am?


Solution

  • After spending some months developing in Android now I can say that the answer to my own question is NO.

    Each Activity has its own Action Bar (if it has) and the only way to share the Action Bar is via the use of Fragments. In that case, we could have have only one Activity with its Action Bar, its Search Widget and everything we like (even its methods!) and only change (replace or add) its actual layout via a Fragment Transaction.

    That is, only change a part of the layout, or all if the Fragment occupies all the space and then having a Dynamic Layout that changes over time based on user interaction and not having to launch many Activities and setting everything up each time.