Kotlin
225 bites tagged Kotlin — interview questions with model answers, and 60-second explainers.
OkHttp Interceptors: Middleware for Your Network Stack
OkHttp Interceptors act as middleware for your network stack, letting you observe, modify, or short-circuit requests and responses. Use them to automatically add auth tokens or log traffic. The main footgun is order: application interceptors run once per call.
Gradle Build Scripts: The Recipe for Your App
Gradle build scripts are your app's recipe, using a declarative DSL to define dependencies and build variants. They manage libraries and create versions like debug vs. release.
Deobfuscating Android Crash Stack Traces
Obfuscated crash reports are useless. Deobfuscation uses a mapping file from your build to translate stack traces back into readable code. This is vital for debugging production apps using R8/ProGuard or native C++.
Kotlin's Job: A Handle to a Background Task
A Job is a handle to a coroutine, letting you manage its lifecycle. You get one from `launch` to control background tasks like network calls. The key footgun: a child's *failure* (Exception) cancels its parent, but a child's *cancellation* does not.
Kotlin Collections: Think Transformations, Not Loops
Treat collection operations as a pipeline, not a `for` loop. Each function (`map`, `filter`) transforms data and passes it to the next stage, ideal for turning API data into UI models.
Kotlin's Control Flow Expressions: `if` and `when`
In Kotlin, `if` and `when` are expressions that return a value. This lets you assign their result directly to a variable, replacing Java's ternary operator. The footgun: when used as an expression, you must have an `else` branch to cover all cases.
ProGuard Keep Rules: A "Do Not Remove" List for Your Code
ProGuard keep rules are a "do not remove" list for Android's code shrinker, telling it what to spare when it can't detect usage. This is crucial for code accessed via reflection or JNI.
Android Work Chaining: An Assembly Line for Tasks
Chaining work in Android is like an assembly line for background tasks, ensuring one task finishes successfully before the next begins. It's used for multi-step operations like fetching, processing, and saving data.
Android Worker: For Deferrable Background Tasks
An Android Worker handles background tasks that must complete, even if the app closes or the device restarts. Use it for reliable, deferrable work like syncing data or uploading logs. The footgun is using it for immediate tasks; the OS can delay its execution.
Android Custom Views: Beyond the Standard Library
A custom view gives you full control over a UI component's drawing and interaction. Use it for unique elements like charts or radial menus that standard widgets can't handle. The footgun is building one when composing existing views would be simpler.
Higher-Order Functions: Passing Code as Data
Higher-order functions treat code as data, accepting other functions as arguments. Lambdas are a concise syntax for creating these function arguments inline, powering collection operations like `map` and `filter` or UI listeners.
Android Network Security Configuration
Define your app's network trust rules in a simple XML file instead of writing complex code. Use it to block cleartext (HTTP) traffic, trust self-signed certs in debug builds, or pin certificates.
Isolating Units for Tests with Mockito-Kotlin
Mockito-Kotlin creates fake objects (mocks) to stand in for real dependencies in your tests. This lets you test a class in isolation, for example, testing a ViewModel without making a real network call. The footgun is testing implementation, not behavior.
CoroutineWorker: Background Tasks with Coroutines
CoroutineWorker simplifies background tasks by letting you use suspend functions inside a WorkManager job. It's for deferrable work, like syncing data, that needs to survive process death.
Dagger's Assisted Injection: Creating Objects with Runtime Data
Assisted Injection lets Dagger provide some dependencies while you supply the rest at runtime. It's for objects that need both graph-provided services and user-supplied data, like a specific ID. The footgun: you can't inject the object, only its factory.
Manual Dependency Injection: No Frameworks, Just Code
Manual dependency injection means you are the 'framework,' creating and passing dependencies yourself via constructors. It's great for simple apps where a full DI library is overkill, but the footgun is creating dependencies inside the class that needs them.
Retrofit Converters: Speaking Your API's Language
A Retrofit Converter is a translator that turns raw network data into your app's data classes (e.g., JSON to Kotlin objects). You add a converter factory, like for Moshi or Gson, when building your Retrofit instance. The footgun: converter order matters.
Android Navigation Actions: Defined Paths, Not Just Destinations
A Navigation Action is a configured pathway between screens, not just a destination. It bundles the target screen with transition animations and arguments. Use them in your XML nav graph to keep UI code clean.
NavController: The Single Source of Truth for App Navigation
NavController is the central API for managing screen transitions. Think of it as an air traffic controller for your UI, directing users between destinations. It's the core of Jetpack Navigation, handling clicks that lead to new screens.
Android Navigation Graph: A Map for Your UI
Think of the Navigation Graph as a visual map of your app's screens. It centralizes all navigation logic in one XML file, defining destinations (screens) and actions (paths between them), simplifying transitions and deep linking.
VectorDrawable: Scalable Graphics for Android
A VectorDrawable is like an SVG for your app, defining images with math, not pixels. Use it for icons that need to look sharp on any screen without bloating your APK. The footgun: complex vectors can be slower to render than a comparable bitmap.
ViewBinding: Say Goodbye to findViewById
ViewBinding generates a type-safe class from your XML layout, giving you direct, non-null access to views with IDs. It's a compile-time safe replacement for `findViewById` used in Activities and Fragments. If a view is missing, you forgot to give it an ID.
In-app Updates: Update Your App Without Leaving It
In-app updates prompt users to update without leaving your app. Use the 'Flexible' flow for routine updates and the 'Immediate' flow for critical fixes. The footgun is overusing the disruptive 'Immediate' flow for non-critical changes.
Play Core Library: Your App's Runtime API to the Play Store
The Play Core Library is your app's direct line to the Google Play Store at runtime. Use it to request features like in-app updates, on-demand modules, or user reviews without leaving the app.
Get Kotlin bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.