tezvyn:

Android & Kotlin

Jetpack Compose, Android Studio, Kotlin, Material You

243 bites

Android & Kotlin30 sec read

Explain launch vs. async in Kotlin Coroutines

Tests your grasp of structured concurrency, return values, and exceptions. `launch` is for fire-and-forget tasks (returns `Job`), while `async` is for tasks that produce a result (returns `Deferred`).

Android & Kotlin30 sec read

What problem does `inline` solve, and how does `reified` relate?

This tests your grasp of Kotlin compiler optimizations and JVM type erasure. Explain that `inline` eliminates the runtime overhead of lambda objects. Then, describe how `reified` leverages inlining to make generic types accessible at runtime.

Android & Kotlin30 sec read

Compare and contrast `apply` and `let` scope functions

Tests Kotlin scope function knowledge: context (`this`/`it`) & return value. `apply` uses `this`, returns the object (for config). `let` uses `it`, returns lambda result (for null-checks/transforms). Red flag: mixing up return values or use cases.

Android & Kotlin30 sec read

When to use a sealed class instead of an enum?

Tests your grasp of Kotlin's type hierarchies. Use `sealed class` for states with associated data (e.g., `Success(data)`), as subclasses can have unique properties. Use `enum` for simple, constant states. A red flag is treating them as interchangeable.

Android & Kotlin30 sec read

Explain and implement a Kotlin higher-order function

Tests understanding of first-class functions and lambda usage. First, define a higher-order function (HOF) as one that takes/returns functions. Then, implement the requested function, iterating to apply the predicate and transform.

Android & Kotlin30 sec read

What are the advantages of a Kotlin data class and its functions?

Tests knowledge of Kotlin's idiomatic features. A good answer explains the main advantage (boilerplate reduction), lists generated functions like toString() and equals(), and describes copy() for immutable state updates.

Android & Kotlin30 sec read

What is a Kotlin extension function? Write one for String.

Tests adding functionality to classes without inheritance. Define extension functions as static utilities, explain their use case (e.g., third-party libs), then write `hasWhitespace` using an idiomatic method like `any`. A red flag is manually looping.

Android & Kotlin30 sec read

Purpose of safe call (`?.`) and Elvis (`?:`) operators

This tests your grasp of Kotlin's idiomatic null safety. Explain the safe call (`?.`) for chaining on nullables and the Elvis operator (`?:`) for providing defaults. Combine them in a one-line example. A multi-line `if/else` is a red flag.

Android & Kotlin30 sec read

Explain val, var, and null safety in Kotlin

This tests your grasp of immutability and Kotlin's compile-time null safety. Define `val` (immutable reference) vs. `var` (mutable), explain nullable types using `?`, and state the risk is `NullPointerException`. A red flag is confusing `val` with a constant.

Android & Kotlin31 sec read

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.

Android & Kotlin30 sec read

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.

Android & Kotlin30 sec read

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 & Kotlin30 sec read

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.

Android & Kotlin30 sec read

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.

Android & Kotlin30 sec read

Perfetto: See Your Whole System on One Timeline

Perfetto is a flight recorder for your system, capturing kernel and app events on a single timeline. Use it to diagnose complex issues like jank by correlating app behavior with system activity.

Android & Kotlin30 sec read

Robolectric: Run Android Unit Tests on the JVM

Robolectric runs Android unit tests on a regular JVM, not a slow emulator. Use it in CI/TDD to test logic like Activity lifecycles without the minutes-long build-deploy cycle. The footgun is over-mocking; Robolectric tests behavior, not just implementation.

Android & Kotlin30 sec read

Handling API State with a Sealed Class Wrapper

Treat API calls as states, not just data. A sealed class wrapper (`Success`, `Error`, `Loading`) models these states for your UI. Use this with Retrofit to show spinners or errors without crashing. The footgun: don't scatter try-catch blocks; centralize them.

Android & Kotlin30 sec read

Kotlinx.serialization: Kotlin's Native Data Converter

Kotlinx.serialization is Kotlin's native way to convert data classes into formats like JSON. It uses a compiler plugin to automate the process, making it ideal for API calls or saving data.

Android & Kotlin30 sec read

Scoped Storage: Your App's Private File Cabinet

Scoped Storage gives your app a private file cabinet on external storage, not a key to the whole building. It's the default on modern Android for saving data or accessing media. The footgun: don't use direct file paths to shared files; you must use new.

Android & Kotlin30 sec read

Compose Layouts: Build UI by Describing It

Describe your UI, and Compose draws it. Use `Column` and `Row` to position elements, then augment them with modifiers. The footgun is coding before you've broken the visual design into reusable parts, leading to a tangled mess.