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

Asked

Viewed 800 times

3

I created a navigation Drawer. To use in several Activities using a standard class for it (DrawerBase.java) and Xtendo her in Activities where I want Navigation Drawer to open, but I have the following problem:

If I am in Activity Home, I open the menu and click on the item corresponding to Activity Home, it is reloaded, as I can do a test in the method OnNavigationItemSelected() of my class DrawerBase 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 recharging the activity?

2 answers

0


I used this code to test before I called 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);
    }

0

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

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

So you won’t be recharging the same activity again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.