How do I return to my ActionBarActivity?

0

For example ... I have an application that has a main ActionBar and in it I "seto" an activity that has a drawerLayout (which has a side menu) ... In each menu option - I selected - I replace the FrameLayout added to my DrawerLayout by a fragment ... How do I configure when I click on the title of my ActionBar or the icon on the left side, it returns to the Activity that the application started - which in the case is not a Fragment -?

    
asked by anonymous 09.04.2015 / 11:36

1 answer

1

Your Activity is the set of Drawer, ActionBar and any Fragments that you add to it. Imagine the Activity as a 'box' on you put 'blocks', which are the Fragments, so every time you select a new item in Drawer it changes the 'block' of your 'box'. "

If you started the Activity it should contain a Fragment 'main', 'home', 'main', as you prefer to call, to be added to your FrameLayout. After navigating the application through the menu, its FrameLayout will be replaced by other Fragments (FragmentManager replace command). If you use the method 'addToBackStack (' name ')' your Activity's FragmentManager will create a stack of Fragments that will be unpinned if you use the 'onBackPressed ()' method.

In case you want to, once you click on a button you see your 'Home' again, just do the replace for your Fragment 'home'. And if you were stacking the Fragments with 'addToBackStack (' name ')' you can clean the stack using:

getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);

And then do the replace for your main fragment:

getSupportFragmentManager().beginTransaction() .replace(R.id.FrameLayout, FragmentMain.newInstance(), "fragmentMain") .commit();

    
09.04.2015 / 20:17