Cheat Sheets

Kotlin Android Cheat Sheet: Activities, Views, Intents & Lifecycle

By ArpaNeuro Team September 17, 2026
Kotlin Android cheat sheet

A Kotlin Android cheat sheet covers the activity (or Compose) entry, how you inflate views, how Intents start screens, and the lifecycle callbacks that survive rotation. Prefer view binding or Compose over findViewById. Keep work off the main thread with coroutines when you hit the network.

This Kotlin cheat sheet is written for people searching for a fast, accurate reference: students, junior developers, and teams shipping production software. Pin it, copy the snippets, and come back when syntax slips.

Quick reference

  • Activity: A screen with a window. onCreate is where you inflate and wire clicks.
  • Lifecycle: onCreateonStartonResume → pause/stop/destroy. Do not leak listeners.
  • View binding: binding.button.setOnClickListener { } — null-safe generated classes.
  • Intent: Intent(this, DetailActivity::class.java).putExtra("id", id).
  • Extras: Read with intent.getIntExtra("id", -1). Default when missing.
  • Manifest: Register activities. exported and intent filters for launchers and deep links.
  • Context: Use applicationContext for long-lived objects. Activity context for UI.
  • Rotation: State dies unless ViewModel / savedInstanceState. Do not stuff large objects in extras.

Copy-paste examples

Start a details activity with an extra

Keep extras primitive. Load the rest from a repository in a ViewModel.

class ListActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding = ActivityListBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.open.setOnClickListener {
            startActivity(
                Intent(this, DetailActivity::class.java).putExtra("id", 41)
            )
        }
    }
}

class DetailActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val id = intent.getIntExtra("id", -1)
        title = "Project $id"
    }
}

Common mistakes

  • Doing network calls in onCreate on the main thread — ANR.
  • Holding an Activity reference in a singleton or static listener.
  • Using !! on findViewById instead of view binding.
  • Putting a huge list in Intent extras and hitting Binder size limits.

FAQ

  1. Activity or Fragment? Modern apps often use a single activity plus fragments or all Compose. Interviews still expect you to know Activity lifecycle.
  1. What is a ViewModel for? UI-related state that survives configuration change. It is not a dumping ground for the whole app graph.
  1. Java activities in a Kotlin app? Interop works. New files should be Kotlin unless you are editing a legacy module.

Related Kotlin cheat sheets

Build with this stack

When a cheat sheet is not enough — you need a production app, a student FYP, or a custom dashboard — ArpaNeuro builds mobile app development and also sells ready-made source code. Request a quote and tell us the stack.

Browse software development services or the source code marketplace if you want a working codebase instead of starting from a blank file.

← All Articles Get a Quote →