Android
433 bites tagged Android — interview questions with model answers, and 60-second explainers.
Android Build Variants: One Codebase, Many Apps
Think of build variants as a matrix for your app builds, combining build types (like debug/release) with product flavors (like free/paid). This lets you manage different API endpoints or features for various versions from a single codebase.
Adding Build Dependencies with Gradle in Android
Gradle is the tool for adding build dependencies to your Android app. This allows you to integrate external libraries like Jetpack, Compose, or Google Play Services, which are essential for building modern applications.
Logcat: The `tail -f` for Android Apps
Think of Logcat as `tail -f` for your Android app, streaming system and application messages from a device in real-time. It's your primary tool for debugging crashes, tracking execution flow, and inspecting variable values as your app runs.
Android App Development: Core Languages and Tools
Android apps are primarily built with Kotlin, Java, and C++ using the official SDK. While other languages are possible, they often need 'glue' code to work and may have restricted API access. The main footgun is assuming any language has first-class support.
AndroidManifest.xml: The Blueprint for Your App
AndroidManifest.xml is the blueprint for your app, telling the OS its components, permissions, and requirements before running any code. A missing declaration here is a common source of runtime crashes, as the OS simply won't see your component.
Android Project Structure: Your App's Filing Cabinet
Think of an Android project as a standardized filing cabinet. It organizes your code, images, and configuration into specific folders so the build system knows where to find everything. This is the foundation of every Android app you build or inspect.
Android Studio: The Official Workshop for Android Apps
Think of Android Studio as the all-in-one workshop for building Android apps. It bundles a code editor, build system, and emulators to write, test, and package software for any Android device. The footgun is underestimating its resource needs.
Kotlin's Type-Safe Builders: Code as Data
Type-safe builders use Kotlin code to create a custom language (DSL) for building complex objects. It's like writing HTML, but the compiler validates your structure. This is common for UI layouts or server configs. The footgun is omitting `@DslMarker`.
Kotlin's `in` and `out`: Declaration-Site Variance
Kotlin's `out` and `in` keywords define a generic class as a producer or consumer at its declaration, avoiding Java's repetitive wildcards. Use `out T` for types only returned (produced) and `in T` for types only consumed.
SharedFlow: A Hot Flow for Broadcasting Events
A SharedFlow is a hot stream that broadcasts values to all subscribers, like a live TV channel. It's ideal for one-to-many events, like UI updates or notifications. The main footgun: it never completes, so `collect` will suspend forever.
Kotlin Delegated Properties: Reusing Getter/Setter Logic
Kotlin's delegated properties let you outsource a property's getter/setter logic. Instead of writing boilerplate, you reuse common patterns like lazy initialization (`by lazy`) or observing changes (`by observable`).
StateFlow: A Hot Flow for UI State
StateFlow is a state-holder observable that emits the current and new state updates to its collectors. Use it to expose UI state from a ViewModel to a UI. The footgun: slow collectors can miss intermediate state updates, receiving only the most recent value.
Kotlin Coroutines: async/await for Parallel Results
async starts a coroutine for a parallel result, returning a `Deferred` value. `await` pauses until that result is ready. Use it to run independent network calls concurrently. The footgun: using it for sequential tasks creates a needless race condition.
Structured Concurrency in Kotlin
Structured concurrency treats async operations like code blocks: a parent task's lifetime contains its children. In Kotlin, a `CoroutineScope` ensures if the parent is cancelled, all its child coroutines are too.
Kotlin Flow: Asynchronous Data Streams
A Kotlin Flow is like an async Sequence, emitting multiple values over time without blocking. It's used for live data from a database or streaming network responses. The footgun: Flows are cold; the code doesn't run until a collector calls `.collect()`.
CoroutineScope: The Parent of Your Coroutines
A CoroutineScope acts as a parent to a group of coroutines, managing their lifecycles. When the parent scope is cancelled, all its children are cancelled too. It's used with builders like `launch` to group related work, like in an Android ViewModel.
Kotlin Coroutines on Android
Kotlin coroutines let Android code write asynchronous logic that reads like sequential code, suspending instead of blocking a thread. Structured concurrency ties each coroutine to a scope, so a destroyed ViewModel cancels its children automatically.
Kotlin Sealed Classes: Enums for Types
A sealed class is like an enum, but for types. It defines a closed set of subclasses, letting each one carry different data. It's perfect for modeling states like `Loading`, `Success`, and `Error`, ensuring you handle every case at compile time.
Kotlin Scope Functions: Cleaner Code, Clearer Choices
Kotlin's scope functions (`let`, `run`, `apply`) create a temporary workspace for an object, avoiding repetitive variable names. Use them for object configuration or chaining calls.
Kotlin Extension Functions: Add Methods Without Inheritance
Kotlin extension functions let you add new functionality to existing classes without inheritance, as if you were adding a new method. They're perfect for creating helpers for third-party library classes or framework types like `String`.
Kotlin Data Classes: Automatic Boilerplate for Data Holders
A Kotlin `data class` automatically generates boilerplate like `equals()` and `toString()` for classes that just hold data. Use it for model objects or DTOs where value equality matters. The footgun: its `copy()` method is shallow, sharing mutable objects.
Kotlin Inheritance: Open for Extension, Closed by Default
In Kotlin, classes are final by default. Think of inheritance as an opt-in feature you enable with the `open` keyword. Use it to create specialized versions of a base class, like a `Student` from a `Person`.
Kotlin Functions: Named, Reusable Code Blocks
A function is a named recipe for your code. You give it ingredients (parameters) and it produces a result. They are used everywhere, from calculating values to handling button clicks.
Kotlin Null Safety: Catch Nulls at Compile Time
Kotlin's type system catches null pointer errors at compile time. Variables are non-nullable by default; you must opt-in to nulls with a `?` (e.g., `String?`). The compiler then forces you to handle the null case. The main footgun is the `!!` operator.
Get Android bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.