AceMobileInterview

Interview guides / android

God MainActivity: Android Interview Question

God MainActivity interview question with a clear example answer for Android engineers. Practice with AceMobileInterview.

This is a common Android interview topic: God MainActivity.

Below is a concise answer you can adapt in a real interview, then go deeper in the full AceMobileInterview track.

  1. 1.MainActivity mixes networking, parsing, prefs, and UI with a hardcoded API key. Refactor the worst smells (≈45–60 min).

    ## Scenario God Activity with a committed secret. ## How to investigate - Skim `MainActivity.kt` responsibilities - Grep for API keys - Find main-thread `FileOutputStream` / prefs heavy writes ## Planted bug 1: Hardcoded API key **Symptom:** Secret in repo **Root cause:** `const val API_KEY = "sk_live_..."` **Fix:** BuildConfig / local properties placeholder; stub in exercise ## Planted bug 2: God object **Symptom:** Untestable **Root cause:** OkHttp + JSON + SharedPreferences + UI in Activity **Fix:** Extract `SettingsRepository` + ViewModel; Activity/Compose only collects state ## Planted bug 3: Main-thread disk write **Symptom:** Hitch on Save **Root cause:** Synchronous write on click handler **Fix:** `Dispatchers.IO`; then toast on Main ## Optimization tips - Interview success = clear boundaries, not perfect DI graph - Mention how you’d unit test the repository ## What to say in the interview - Secret removal first - What you deferred on purpose

Keep going with AceMobileInterview

Reading helps. Timed practice locks it in. Jump into the interactive track for algorithms with LeetCode links, studio projects, debugging zips, and mobile system design.

iOS trackAndroid trackMore guides