Bridging the gap between static UI layouts and a production-ready mobile application is a defining step in Android development. As part of my Android development internship with Valentius Kryptix, I recently completed my API-Connected Android App milestone—a multi-screen Kotlin application built entirely with Jetpack Compose, live REST API integration via Retrofit, and offline persistence powered by Room.
Instead of relying on hardcoded mock data or legacy XML layouts, this project combines declarative UI design with clean MVVM architecture so the app stays responsive and functional even without an active internet connection.

1. App Overview & Four-Screen Navigation
Using Jetpack Compose and Navigation Compose, I structured the user experience around four distinct screens (MainScreen, ListScreen, DetailScreen, and BrowserScreen), replacing traditional multi-activity XML boilerplate with a unified Compose navigation graph:
- MainScreen (Home): Acts as the central navigation hub, letting users jump directly to either the API-backed post feed or the built-in web launcher.
- ListScreen: Fetches live post items from the JSONPlaceholder REST API (
[https://jsonplaceholder.typicode.com/posts](https://jsonplaceholder.typicode.com/posts)), displays them in a scrollable list, and supports pull-to-refresh to sync fresh updates on demand. - DetailScreen: Displays the selected post’s title prominently at the top alongside its full body description when tapped from the list.
- BrowserScreen: Provides a URL input field that launches links externally on the device using an Android implicit intent.


2. Clean MVVM Architecture & Package Structure
To keep business logic decoupled from UI rendering, I organized the codebase into three primary layers (data, ui, and viewmodel) following the MVVM (Model-View-ViewModel) and Repository patterns:
<package>/ ├── data/ (PostEntity, PostDao, AppDatabase, PostRepository, PostApi) ├── ui/ (MainScreen, ListScreen, DetailScreen, BrowserScreen, theme) └── viewmodel/ (PostViewModel)
PostApi& Retrofit + Gson: Handles asynchronous HTTP GET requests to JSONPlaceholder and deserializes JSON payloads into Kotlin models off the main thread using Kotlin Coroutines.PostViewModel: Exposes reactive UI state streams to the Compose screens while surviving configuration changes.PostRepository: Coordinates data flow between the remotePostApiand the local Room database (AppDatabaseandPostDao).
3. Offline-First Caching with Room (Single Source of Truth)
A key requirement for this milestone was ensuring the app still displays useful content when offline. Rather than treating the local database as an afterthought, I configured Room as the Single Source of Truth:
Compose UI → ViewModel → Repository → Retrofit (network)
↘ Room (local cache)
- Reactive Observation:
ListScreenobservesPostDaocontinuously through a Kotlin Flow, immediately rendering whatever posts are already stored on the device. - Background Synchronization: When the screen opens or the user triggers a pull-to-refresh gesture,
PostRepositoryfetches the latest posts via Retrofit and writes them intoPostEntityrows in Room. - Seamless Offline Fallback: Because the UI reads directly from Room, any previously synced posts remain completely browsable when airplane mode is turned on or signal drops.
4. Handling Loading and Error States Gracefully
Silent network failures and unhandled exceptions quickly ruin user trust. Across the data and UI layers, I accounted for real-world connectivity edge cases:
- Initial Loading State: Displays a visible loading spinner while the app performs its first fetch.
- First-Launch Offline Error: If the device is offline on a fresh install with an empty Room cache, the UI catches the network failure and renders a clear error message paired with a Retry button rather than crashing.
- Cached Offline Resilience: Once data has been synced at least once, subsequent offline launches fall back smoothly to the last-synced Room cache without blocking the user.

5. Key Takeaways & Source Code
Building this project from the ground up solidified how Jetpack Compose, Retrofit, Coroutines/Flow, and Room fit together in modern Android engineering. Designing around a single source of truth eliminated UI flicker, simplified state management in PostViewModel, and made offline support predictable.
The complete source code, architecture notes, and setup instructions are available on GitHub: Android-Internship-Project on GitHub (no API key required—simply clone, sync Gradle in Android Studio, and run).



Leave a Reply
You must be logged in to post a comment.