android – Navigation Drawer calling Activity – Close menu by clicking Activity item if it is current

Question:

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, but I have the following problem:

If I'm in Activity Home, I open the menu and click on the item corresponding to activity Home, 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 one from the activity that I am already and call the command to close the drawer instead of reloading the activity ?

Answer:

You can do it another way, add a rule to the manifest:

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

So it won't reload the same activity again.

Scroll to Top
AllEscort