Skill

Generate Kotlin Android Activities

Generates well-structured Kotlin Android Activities with MVVM, View Binding, lifecycle handling, and navigation patterns.


78
Spark score
out of 100
Updated 7 months ago
Version 1.0.0
Models

Add to Favorites

Why it matters

Generate well-structured, maintainable Kotlin Activities for Android development, adhering to modern best practices like lifecycle management, View Binding, and MVVM patterns.

Outcomes

What it gets done

01

Generate Activity code with proper lifecycle management.

02

Implement View Binding or Compose for type-safe view access.

03

Structure code for testability and maintainability.

04

Incorporate coroutines for asynchronous operations.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/vb-kotlin-activity-generator | bash

Overview

Kotlin Activity Generator

Generates well-structured Kotlin Android Activities using MVVM, View Binding, and lifecycle best practices, with full detail-screen and searchable-list-screen examples. Use when scaffolding a new Android Activity or refactoring an existing one toward MVVM with proper state and navigation handling.

What it does

Generates well-structured, maintainable Kotlin Android Activities following modern best practices - proper lifecycle management, View Binding, MVVM architecture, coroutines, and Material Design-aligned navigation patterns.

When to use - and when NOT to

Use this skill when scaffolding a new Android Activity, refactoring an existing Activity toward MVVM, implementing a detail screen backed by a ViewModel, or building a list screen with search, filtering, and pagination. Not a fit for Jetpack Compose-only screens without an Activity/View Binding structure, or for non-Android Kotlin code. It also covers using appropriate Activity launch modes and properly handling intent filters for deep links as part of the navigation guidance.

Inputs and outputs

Provides a base Activity structure template with onCreate broken into discrete setup steps (binding, ViewModel, observers, click listeners, intent handling) for consistent, readable Activity code.

Includes a full MVVM example (ProductDetailActivity) showing: a companion object factory method for type-safe Intent creation, View Binding setup, toolbar and RecyclerView configuration, LiveData observers for product/loading/error state, image loading via Glide, error display via Snackbar with a retry action, and share-intent construction.

Includes a second full example (ProductListActivity) covering a searchable, filterable list screen: RecyclerView adapter with item-click and favorite-click callbacks, infinite-scroll pagination via a scroll listener, swipe-to-refresh, and a SearchView integrated into the options menu with query text listeners.

Best-practice guidance covers state management (handling configuration changes, ViewModel for surviving state, sealed classes for UI state), performance (View Binding over findViewById, proper RecyclerView/ViewHolder patterns, lifecycle-aware coroutines, pagination), error handling (validating intent extras, retry mechanisms), navigation (companion-object intent factories, launch modes, deep links), and testability (separating business logic into ViewModels, injectable dependencies, interface-based external dependencies).

It also emphasizes proper saved-state handling for critical UI state across configuration changes, proper back-navigation handling, wrapping fallible operations in try-catch blocks, and keeping Activities focused specifically on UI binding and user interactions while exposing testable methods as internal where needed.

Integrations

Built on AppCompatActivity, View Binding, Android ViewModel/LiveData, RecyclerView, and coroutines, with the example code additionally using Glide for image loading and Material Snackbar for error UI. The list-screen example also wires the options menu SearchView directly to the ViewModel's search and clear-search methods, and the detail-screen example includes a share-intent builder using Intent.ACTION_SEND so the share flow stays consistent with the rest of the Activity's ViewModel-driven state.

Who it's for

Android developers who need a consistent, testable Activity structure and concrete MVVM examples (detail screen, searchable list screen) rather than a general Android architecture overview.

private fun setupViewModel() {
    viewModel = ViewModelProvider(this)[MainViewModel::class.java]
}

FAQ

Common questions

Discussion

Questions & comments ยท 0

Sign In Sign in to leave a comment.