Go back to a Fragment from a ActionBarActivity with the app icon as an up button?

Cristiam Mercado

I have this GUI to select some Fragments I have in the application. When I select the "Empleados" option, a ListView inside a Fragment appears like this:

    <activity
        android:name=".actividades.admin.InicioAdmin"
        android:theme="@style/AppTheme">
    </activity>

Navigation Drawer

This is the switch where I inicialize the Fragment.

    Fragment fragment = null;

    switch (posicion) {
        case 0:
            fragment = new HomeFragment();
            break;
        case 1:
            fragment = new EmpleadoFragment();
            break;
        case 3:
            UsuarioFunciones.cerrarSesion(context);
            Intent inicio = new Intent(getApplicationContext(), Login.class);
            inicio.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(inicio);
            finish();
            Toast.makeText(context,"Sesión finalizada",Toast.LENGTH_LONG).show();
            break;
        default:
            break;
    }

    if (fragment != null) {
        getSupportFragmentManager().beginTransaction().replace(R.id.content_frame,
                fragment).commit();
        listView.setItemChecked(posicion, true);
        listView.setSelection(posicion);
        setTitle(navMenuTitulos[posicion]);
        drawerLayout.closeDrawer(listView);
    }

EmpleadoFragment.java (extends Fragment)

Lista

When selecting an employee, it loads a ActionBarActivity where you can do some functions for that employee.

My question is how can i run the navigation button back to reopen the Fragment where is the ListView?.

Back Button

When I press the physical "Back" button the ListView is reopened, but with the App Icon not working.

AndroidManifest.xml for the ActionBarActivity above (DetalleEmpleado.java):

<activity
    android:name=".actividades.admin.DetalleEmpleado"
    android:label="@string/actividad_detalle_empleado"
    android:theme="@style/AppTheme"
    android:parentActivityName=".SampleParentActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".SampleParentActivity"/>
</activity>
luiscarlostic

You must put the code to return in the onOptionsItemSelected of your ActionBarActivity. Here you can find more information.

@Override
 public boolean onOptionsItemSelected(MenuItem item) {
     switch (item.getItemId()) {

        case android.R.id.home:
            //Close current activity
            finish();
        return true;    

         default:
             return super.onOptionsItemSelected(item);
     }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Go back to a Fragment from a ActionBarActivity with the app icon as an up button?

From Dev

ActionBarActivity back button not popping from backstack

From Dev

How to go to root activity from any fragment by pressing back button?

From Dev

How to go to root activity from any fragment by pressing back button?

From Dev

Open ActionBarActivity from fragment

From Dev

navigation icon and back button not showing up in ionic

From Dev

Navigate back to the respective Fragment using up button

From Dev

go back button between "grand child" fragment

From Dev

Changing the UINavigationBar back button to an icon and retaining the swipe to go back

From Dev

How to go back to previous fragment from activity?

From Dev

How to go switch back to the MainActivity from a fragment?

From Dev

Go back to a Fragment from an Activity onBackpress

From Java

Remove text from Back button keeping the icon

From Dev

Android - Back button from FragmentActivity to another Fragment

From Dev

App closing when pressing go back button

From Dev

Manage toolbar's navigation and back button from fragment to fragment in android

From Dev

Back Button Arrow from Fragment to previous home fragment

From Dev

Facebook login button not showing up in ActionbarActivity

From Dev

going back to the parent activity on pressing app icon button

From Dev

going back to the parent activity on pressing app icon button

From Dev

Hiding ActionBar from ActionBarActivity after a Splash Fragment

From Dev

App closes on pressing back button when trying to move to previous fragment

From Dev

Blank activity or fragment on reopening app after closing by pressing back button

From Dev

Fragment pressing back button

From Dev

MaterialDrawer back button in fragment

From Dev

Back button in fragment

From Dev

Adding back button to fragment

From Dev

How to go back to app from play store

From Dev

Android: How can I navigate from one "detail" to another "detail", while having the "Up" button go back to the "Master" list?

Related Related

  1. 1

    Go back to a Fragment from a ActionBarActivity with the app icon as an up button?

  2. 2

    ActionBarActivity back button not popping from backstack

  3. 3

    How to go to root activity from any fragment by pressing back button?

  4. 4

    How to go to root activity from any fragment by pressing back button?

  5. 5

    Open ActionBarActivity from fragment

  6. 6

    navigation icon and back button not showing up in ionic

  7. 7

    Navigate back to the respective Fragment using up button

  8. 8

    go back button between "grand child" fragment

  9. 9

    Changing the UINavigationBar back button to an icon and retaining the swipe to go back

  10. 10

    How to go back to previous fragment from activity?

  11. 11

    How to go switch back to the MainActivity from a fragment?

  12. 12

    Go back to a Fragment from an Activity onBackpress

  13. 13

    Remove text from Back button keeping the icon

  14. 14

    Android - Back button from FragmentActivity to another Fragment

  15. 15

    App closing when pressing go back button

  16. 16

    Manage toolbar's navigation and back button from fragment to fragment in android

  17. 17

    Back Button Arrow from Fragment to previous home fragment

  18. 18

    Facebook login button not showing up in ActionbarActivity

  19. 19

    going back to the parent activity on pressing app icon button

  20. 20

    going back to the parent activity on pressing app icon button

  21. 21

    Hiding ActionBar from ActionBarActivity after a Splash Fragment

  22. 22

    App closes on pressing back button when trying to move to previous fragment

  23. 23

    Blank activity or fragment on reopening app after closing by pressing back button

  24. 24

    Fragment pressing back button

  25. 25

    MaterialDrawer back button in fragment

  26. 26

    Back button in fragment

  27. 27

    Adding back button to fragment

  28. 28

    How to go back to app from play store

  29. 29

    Android: How can I navigate from one "detail" to another "detail", while having the "Up" button go back to the "Master" list?

HotTag

Archive