On this page
Legacy code is code that works and that people are afraid to change. The fear comes from not knowing what it does or what depends on it. AI can explain code at the speed you can read, generate maps of flows, and draft tests that capture current behaviour.
A comprehension-first approach
Prompts for each step
Based on these files (manifest, build.gradle, package list), describe the app's main modules,
entry points (Activities, Services, Receivers), networking and storage approach, and third-party SDKs.
Flag anything deprecated (AsyncTask, Loaders, legacy support libraries).Trace what happens from tapping "Place order" in CheckoutActivity to the confirmation screen:
list each class/method in order, which thread it runs on, network calls, database writes and
any static/global state touched. Mark places where errors are swallowed.Explain OrderManager.java: responsibilities, inputs/outputs, side effects, thread safety.
Then list risks if we change it: callers, static state, implicit ordering, reflection, and
behaviour that tests should capture before refactoring.Verify what AI tells you
- Step through the traced flow with the debugger. AI can misread callbacks and dynamic dispatch.
- Use Android Studio's Find Usages and call hierarchy to confirm dependencies.
- Check runtime behaviour in Logcat. Legacy code often depends on side effects that static reading misses.
Characterization tests with AI help
class LegacyDiscountCalculatorTest {
// Generated as drafts by AI from reading the Java source, then verified by running them.
@Test fun `discount above 100 percent is clamped to zero price`() {
assertEquals(0.0, LegacyDiscountCalculator.apply(500.0, 120), 0.001)
}
@Test fun `negative price returns zero (legacy behaviour, keep for now)`() {
assertEquals(0.0, LegacyDiscountCalculator.apply(-10.0, 10), 0.001)
}
}Characterization tests record what the code does, not what it should do. Confirm odd behaviours with the product team before "fixing" them.
Then migrate safely
- Convert one class to Kotlin (Android Studio's converter or AI), keeping behaviour identical.
- Run the characterization tests, then improve idioms (nullability, data classes) in a separate commit.
- Extract logic from Activities into ViewModels and repositories. See Refactoring Legacy Apps.
Real-world uses
Onboarding
New developers generate a codebase map and flow traces in their first week, verified with a mentor.
Bug fixing in unknown code
Explain the module, add a characterization test, fix, keep the test.
Migration planning
AI inventories deprecated APIs and risky classes to prioritise the roadmap.
Frequently asked questions
Can I paste the whole codebase into an AI chat?
Usually not effective, and possibly against policy. Use IDE-integrated tools with project context, focused on specific modules, and follow data-sharing rules.
Is AI-converted Kotlin idiomatic?
Often not. Expect !!, lateinit overuse and Java-style patterns. Convert first, then refactor idioms with tests in place.
What if the AI explanation is wrong?
That's why you verify with the debugger and tests. Treat explanations as hypotheses.
Conclusion
AI turns legacy comprehension from weeks into days: map, trace, explain, assess risk and capture behaviour, all verified with the debugger and tests, before making small, safe changes.
Next step: modernise the UI layer with AI-Assisted Migration from XML to Jetpack Compose.
Official references
๐ฑ Apps built by Yunok Tech
Real Android apps on Google Play, free to download.
Walzi4K wallpapers for lock and home screenGet it โธ
NotiVaultNotification history: recover dismissed notificationsGet it โธ
Ready to build real Android applications?
AI coding tools multiply what you already know. The stronger your Kotlin, Compose and architecture foundation, the better you can judge, fix and ship what these tools suggest.
Move beyond theory and strengthen your Android development skills with Yunoktech's Android course. Learn core concepts, practical implementation, modern Android development techniques, and the reasoning behind building maintainable applications.
Explore the Android course and take your next step as an Android developer.