I have this BaseDrawerActivity (I haven't pasted the whole activity, justr the relevant parts. If you need any more information, please let me know):

public abstract class BaseDrawerActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    protected DrawerLayout drawerLayout;
    protected NavigationView navigationView;
    protected ActionBarDrawerToggle drawerToggle;

    // Initialize the drawer in the derived activity’s ‘onCreate’ method.
    protected void initializeDrawer() {
        drawerLayout = findViewById(R.id.drawer_layout);
        navigationView = findViewById(R.id.nav_view);
        drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.open, R.string.close);
        drawerLayout.addDrawerListener(drawerToggle);
        drawerToggle.syncState();
        Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
        navigationView.setNavigationItemSelectedListener(this);
    }

    // Handle drawer item selected in one place.
    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        // Your navigation item handling code…
        int id = item.getItemId();
        navigationView.bringToFront();

        if (!(this instanceof MainActivity) && id == R.id.home) {
            Toast.makeText(BaseDrawerActivity.this, "Home pressed", Toast.LENGTH_SHORT).show();
            finish();
        } else if (!(this instanceof LeaderboardActivity) && id == R.id.leaderboard) {
            Toast.makeText(BaseDrawerActivity.this, "Leaderboard pressed", Toast.LENGTH_SHORT).show();

            if (FirebaseDatabaseUtil.changedSinceSynced) {
                FirebaseDatabaseUtil.changedSinceSynced = false; //sync is done here, not using onStop
                FirebaseDatabaseUtil.saveToDB(false, new FirebaseDatabaseUtil.DbOperationCompleteListener() {
                    @Override
                    public void onDbOperationComplete() {
                        openLeaderboardActivity();
                    }
                });
            } else {
                openLeaderboardActivity();
            }
        } else if (id == R.id.chatroom) {
            Toast.makeText(BaseDrawerActivity.this, "chatroom pressed", Toast.LENGTH_SHORT).show();
        }/*else if (id == R.id.login) {
            Toast.makeText(BaseDrawerActivity.this, "Login pressed", Toast.LENGTH_SHORT).show();
        }*/else if (id == R.id.share) {
            share();
        } else if (!(this instanceof MessageMeActivity) && id == R.id.chat_with_me) {
            Toast.makeText(BaseDrawerActivity.this, "chat_with_me pressed", Toast.LENGTH_SHORT).show();
            openMessageMeActivity();
        }

        // Close drawer after item is selected.
        drawerLayout.closeDrawer(GravityCompat.START);
        return false; // return true if you want to indicate the item was selected.
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (drawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }



Help me fix it. It does not work as intended. For example: I open the app, the MainActivity opens. Then, I go to LeaderboardActivity, then from there, I go to MessageMeActivity. When I press the home button in this situation, instead of going back to Home, it goes only one step back to LeaderboardActivity, like if I've pressed a back button. Help me fix this issue for all possible combinations.