# Android Navigation Drawer with Conditional Sync

> Implement navigation logic in a BaseDrawerActivity that clears the activity stack using Intent flags while preserving specific pre-navigation data synchronization checks (like Firebase) for certain destinations.

- Skill: `ecnu-icalk/android-navigation-drawer-with-conditional-sync` (Agent Skill)
- Install (CLI): `npx skillmds@latest add ecnu-icalk/android-navigation-drawer-with-conditional-sync`
- Raw SKILL.md: https://api.skillmd.com/api/skills/ecnu-icalk/android-navigation-drawer-with-conditional-sync/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: ECNU-ICALK (https://skillmd.com/u/ecnu-icalk)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/ecnu-icalk/android-navigation-drawer-with-conditional-sync

---


# Android Navigation Drawer with Conditional Sync

Implement navigation logic in a BaseDrawerActivity that clears the activity stack using Intent flags while preserving specific pre-navigation data synchronization checks (like Firebase) for certain destinations.

## Prompt

# Role & Objective
Act as an Android Developer. Implement navigation logic for a `BaseDrawerActivity` that handles menu item clicks. The goal is to fix navigation stack issues (e.g., returning to Home instead of just the previous activity) while maintaining existing data synchronization requirements.

# Operational Rules & Constraints
1.  **Stack Clearing:** When navigating to a destination (e.g., Home, Leaderboard, Chat), do not simply call `finish()`. Instead, start the target Activity using an Intent with `Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP` to ensure the back stack is cleared correctly and the target activity is brought to the front.
2.  **Instance Check:** Before starting an activity, check `if (!(this instanceof TargetActivity))` to avoid restarting the current activity unnecessarily.
3.  **Firebase Sync Preservation:** For specific activities (e.g., `LeaderboardActivity`), strictly preserve the existing data synchronization logic. If `FirebaseDatabaseUtil.changedSinceSynced` is true, perform the save operation and navigate in the `onDbOperationComplete` callback. Otherwise, navigate directly.
4.  **Consistency:** Apply the stack clearing logic to all relevant menu elements to ensure consistent navigation behavior across the app.

# Anti-Patterns
Do not remove existing asynchronous database checks when updating navigation logic. Do not use `finish()` for global navigation if the goal is to return to a specific root activity regardless of stack depth.

## Triggers

- fix navigation drawer back stack
- implement navigation logic for menu elements
- preserve firebase logic in navigation
- clear activity stack from drawer

