Navigation Drawer by calling Activity - Close the menu by clicking on the Activity item if it is the current one

3

I created a navigation drawer. To use in several Activities using a default class for it ( DrawerBase.java ) and extend it in Activities where I want the Navigation Drawer to open, however I have the following problem:

If I am in Activity Home, I open the menu and click on the Activity Home item, it is reloaded, how can I test the OnNavigationItemSelected() method of my DrawerBase class to check if the item I clicked to open is the activity that I am already and call the command to close the drawer instead of reloading the activity ?

    
asked by anonymous 18.12.2015 / 14:37

2 answers

0

I used this code to test before calling Intent:

if (id == R.id.home) {
    if(this.getClass().getSimpleName().equals("HomeActivity")){
       drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    }else{
       Intent i = new Intent(this, HomeActivity.class);
        startActivity(i);
    }
    
18.12.2015 / 18:20
0

You can do this differently, add a rule to the manifest:

<activity
    android:name=".Home"
    android:launchMode="singleTask">

So you will not reload the same activity again.

    
18.12.2015 / 14:47