Kotlin Advanced Concepts — Android Focus
(Non■Compose)
A deep dive for senior Android engineers (10+ years). Covers advanced language features, concurrency, Flow,
architecture, performance, security, Java interop, Gradle (Groovy), testing, and Android■specific patterns with XML
views.
Authoring Notes
This guide assumes familiarity with Android app fundamentals, MVVM, Retrofit/Room, and Dagger/Hilt. Jetpack
Compose is intentionally excluded per scope. Build scripts use Groovy, not Gradle Kotlin DSL.
Table of Contents
1. Type System Deep Dive
2. Advanced Generics & Variance
3. Inline Classes & Value Types
4. Inline/Reified/Tailrec/Contracts
5. Lambdas with Receiver & DSLs
6. MVVM + Clean Architecture (XML UI)
7. Structured Concurrency in ViewModel
8–47. Android Kotlin Advanced Topics (see sections)
48–50. Appendices
1. Kotlin Type System Deep Dive
Null-safety, platform types from Java interop, and compiler contracts for smart-cast aware APIs.
@OptIn(ExperimentalContracts::class)
fun <T> requireNotNullContract(x:T?):T { contract { returns() implies (x!=null) }; return requireNotNul
Notes: Normalize platform types at Android boundaries.
2. Advanced Generics & Variance
Use-site variance (`in`/`out`) and star projection for APIs that must be generic without giving up safety.
interface Mapper<in I, out O>{ fun map(i:I):O }
Notes: Use `in` for sinks (consumers) and `out` for sources (producers).
3. Inline Classes & Value Types
Value classes give domain safety with near-primitive performance; beware boxing at generics.
@JvmInline value class UserId(val raw:Long)
Notes: Add Room TypeConverters for custom value classes.
4. Inline/Reified/Tailrec/Contracts
Inlining reduces allocation; reified types enable runtime checks; tailrec optimizes recursion.
inline fun <reified T> fromJson(g:Gson, s:String):T = g.fromJson(s, T::class.java)
Notes: Avoid over-inlining very large functions.
5. Lambdas with Receiver & DSLs
Receivers enable type-safe builders for dialogs, permissions, and view inflation helpers.
fun dialog(ctx:Context, build:Ui.()->Unit) = AlertDialog.Builder(ctx).apply{ Ui().build() }.create()
Notes: Prefer explicit receivers when nesting builders.
6. MVVM + Clean Architecture (XML UI)
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
7. Structured Concurrency in ViewModel
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
8. Delegation & Property Delegates
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
9. Reflection & Annotations (KAPT/KSP)
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
10. Operator Conventions
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
11. Collections, Sequences & Performance
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
12. Coroutines: Exception Handling
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
13. Channels & Actors
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
14. Testing Flows & Coroutines
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
15. Android Lifecycle Integration
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
16. Room & Transactions
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
17. WorkManager Patterns
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
18. Networking
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
19. Caching & Offline-First
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
20. Java Interop
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
21. Gradle & Build Optimization (Groovy)
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
22. R8/ProGuard
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
23. Security & Permissions
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
24. Memory & Leak Prevention
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
25. Performance Tuning
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
26. Threading Model & Main Safety
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
27. Error Handling & Result Types
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
28. Eventing with SharedFlow
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
29. API Design & Binary Compatibility
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
30. Kotlin Multiplatform (Android-centric)
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
31. Serialization
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
32. Time & Locale
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
33. Resources & I18n
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
34. BLE & System Services
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
35. Custom Views & Drawables
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
36. Thread-Safe Caches
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
37. RecyclerView Patterns
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
38. ANR Avoidance
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
39. SDK/Library Design
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
40. Style & Idioms
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
41. Migration from Java/Rx
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
42. Feature Flags & Remote Config
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
43. Crash Resilience
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
44. Build Variants & DI
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
45. Release Engineering & Keep Rules
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
46. Flow Backpressure & Buffering
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
47. Cold→Hot Conversion (stateIn/shareIn)
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
48. Flow Testing (Turbine-like)
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
49. Cancellation, Timeouts, Cleanup
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
50. Retry/Repeat/Supervision Patterns
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
51. MVVM Diagram (Recap)
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
52. Concurrency Diagram (Recap)
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
53. Appendix A — Coroutines & Flow Cheat Sheet
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
54. Appendix B — Code Review Checklist
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
55. Appendix C — R8/ProGuard Recipes
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.
56. Appendix D — Testing Patterns
Deep explanation and Android-specific guidance for senior teams.
// See full examples earlier; adapt to your app's architecture.