Network and offline

Network calls off the main thread, timeouts and retries, then offline-first: the local database as source of truth, the queue of pending writes, synchronisation and conflicts.

  • 30 cards
  • 7 topics
  • Free

The outline, topic by topic

Each topic is weighted the way the exam weighs it.

  1. Concepts
  2. Questions
  3. The numbers
  4. On the diagram
  5. The steps
  6. Scenarios
  7. Understand

A few cards from the deck

  • Offline-first: what is it?

    Show the answer

    A way of designing the app where the screen always reads and writes the phone's database, the network only stepping in separately to exchange with the server.

    The app stays usable on the subway or on a plane: a network outage delays data updates, it no longer blocks the screen.

  • Which exception does this code raise when the user taps the button?

    ```kotlin
    button.setOnClickListener {
    val texte = URL("https://api.exemple.fr/notes").readText()
    liste.text = texte
    }
    `

    • android.os.NetworkOnMainThreadException
    • java.net.SocketTimeoutException
    • java.lang.SecurityException
    • java.io.FileNotFoundException
    Show the answer

    android.os.NetworkOnMainThreadException

    The click handler runs on the main thread, where Android forbids network access. The call must be launched in a coroutine or another thread, then the screen updated on return.

  • A network call never runs on the …, otherwise the screen freezes and, after about … seconds, the system shows "app not responding".

    Show the answer

    A network call never runs on the main thread, otherwise the screen freezes and, after about 5 seconds, the system shows "app not responding".

    The call is handed to another thread (coroutine, executor) and execution returns to the main thread to show the result.

  • Source of truth: what is it?

    Show the answer

    The single place in the app where data is authoritative, and which every screen reads.

    In an offline-first app it is the local database: the API response is written there, the screen never displays it directly.