Android cheat sheet
A scannable Android reference: 7 short snippets across 6 topics, each linking back to the lesson it came from.
At a glance
| Topic | What it covers | |
|---|---|---|
| Android projects and activities | An Android app is a Gradle project. The root build file configures the build for every module; the app module is the | lesson |
| Permissions, storage and publishing | Normal permissions are granted at install time just by declaring them. Dangerous permissions — camera, location | lesson |
| Local persistence with Room and DataStore | Use DataStore for preferences: it is asynchronous, transactional and typed. SharedPreferences applies changes to disk | lesson |
| Testing Android apps | JVM versus instrumented tests, coroutine test dispatchers, fakes over mocks, Compose UI testing and screenshot tests | lesson |
| Performance, accessibility and Play quality | Run the pre-launch report before every release. It tests on real devices, flags crashes, accessibility issues and | lesson |
| Next steps: Kotlin Multiplatform and the Jetpack ecosystem | Foldables, tablets and ChromeOS all run the same app. Branching on screen width rather than device model is the | lesson |
Quick snippets
Android projects and activities
The activity lifecycle
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val startCount = savedInstanceState?.getInt("count") ?: 0
setContent { AppScreen(initial = startCount) }
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putInt("count", 3)
}
}Full lesson: Android projects and activities →
Permissions, storage and publishing
Requesting permissions
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
Where files belong
// private file inside the app sandbox
val notes = File(context.filesDir, "notes.txt")
notes.writeText("remember to ship")
val restored = notes.readText()
// let the user pick a destination for an export, no storage permission needed
val create = registerForActivityResult(
ActivityResultContracts.CreateDocument("text/plain")
) { uri -> uri?.let { context.contentResolver.openOutputStream(it)?.use { s ->
s.write(restored.toByteArray())
} } }
create.launch("notes.txt")Full lesson: Permissions, storage and publishing →
Local persistence with Room and DataStore
Migrations and relations
val Context.settings: DataStore<Settings> =
dataStore("settings", serializer = SettingsSerializer)
// a DataStore update is atomic and exposes the change as a flow
suspend fun setDarkMode(enabled: Boolean) {
context.settings.updateData { it.copy(darkMode = enabled) }
}
val darkMode: Flow<Boolean> = context.settings.data.map { it.darkMode }Full lesson: Local persistence with Room and DataStore →
Testing Android apps
Compose UI tests
// screenshot testing makes layout regressions visible in review
@Test fun booksScreenLightTheme() {
captureRoboImage("build/screenshots/books-light.png") {
AppTheme(darkTheme = false) { BooksScreen(sampleState, {}, {}) }
}
}Full lesson: Testing Android apps →
Performance, accessibility and Play quality
Accessibility and Play quality
# Play vitals that affect search and promotion
# ANR rate crashes and freezes in the foreground
# crash rate including background crashes
# excessive wakeups battery drain reported by the platform
# stuck partial wakelocks
#
# and store requirements, which change every year:
# targetSdk within the current window
# a privacy policy for anything collecting data
# a data safety declaration that matches the SDKs you shipFull lesson: Performance, accessibility and Play quality →
Next steps: Kotlin Multiplatform and the Jetpack ecosystem
Jetpack libraries worth adopting
// adaptive layout without branching on device type
@Composable
fun BookScreen(windowSizeClass: WindowSizeClass, state: BookUiState) {
when (windowSizeClass.widthSizeClass) {
WindowWidthSizeClass.COMPACT -> BookListOnly(state)
WindowWidthSizeClass.MEDIUM -> BookListAndPreview(state)
else -> BookListPreviewAndDetail(state)
}
}
// compute it from the activity window
val windowSizeClass = calculateWindowSizeClass(activity)Full lesson: Next steps: Kotlin Multiplatform and the Jetpack ecosystem →
FAQ
Is this Android cheat sheet free to use?
Yes. No sign-up and no tracking: the page is static, every example is on the page itself, and you can print it or save it as a one-page reference.
Where do the examples come from?
Every snippet is taken from the 6 lessons of the Android course on this site, and each section links back to the lesson it was pulled from.
How do I go deeper than a cheat sheet?
Open the full Android course — it carries the worked explanations, the edge cases and the exercises behind every line here.
Related cheat sheets
iOS Flutter React Native Kotlin Swift
Last refreshed 2026-09-27.