0

I have DrawerParent class which is basically a drawer. And, say, two activities inherited from DrawerParent. What I want is to not re-open same activity if it is already running. For such thing I need to somehow check whether this activity is running or not. It works like this in drawer:

public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_about) {

            startActivity(new Intent(this, AboutActivity.class));
            finish();

        } else ...

And I don't know how to check it. Thank you.

== Edit ==
Making group in layout and adding selectable="single" not works.

Cakeee
  • 49
  • 9

1 Answers1

1

If you are running that code on the activity, you can compare using:

if (!(this instanceof ActivityToBeOpened)) {
   startActivity(new Intent(this, ActivityToBeOpened.class));
   finish();
}

You can get more info about instanceof here.

Hope it helps!

Natan
  • 1,867
  • 13
  • 24