Posts

Showing posts from September, 2025

Typesafe HTML DSL Example

Image
  Want to use HTML in your app? Just a small post for today. Using  Typesafe HTML DSL , you can do this: Full (small) code listing: package ... import android.webkit.WebView import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.padding import androidx.compose.material3.Card import androidx.compose.material3.Scaffold import androidx.compose.runtime. Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidView import kotlinx.html.* import kotlinx.html.dom.* import org.w3c.dom.Document object CoolLittleHtmlExample { private fun createHtmlPage () = createHTMLDocument (). html { head { title = "My Cool little HTML Kotlin Page" // Not displayed } body { h1 { + "Hello from D9!" } p { + "This is a paragraph generated by HTML DSL." } b { + "Let's be bold " } i ...

Process Death - Part 2: Minimal Example Apps

Image
Introduction This is part of a short series of posts about Process Death and how to mange it in the Modern Android Compose environment. I strongly recommend reading these in order. Process Death - Part 1: Introduction and Overview An overview and a short code example to demonstrate Process Death - Part 2: Minimal Example Apps Examples of remember, not saving, crashing, and restoring values after Process Death Process Death - Part 3 - TBA but likely when and how to save more complex states Example App 1: Remember vs. RememberSavable Here's a tiny app with two counters you increment at the same time. Here's a full link to the code: Git Hub Gist Link It will increment both the rememberCounter and the rememberSavable counter. If leave the app and come back, both of these should remain the same unless you hit Process Death.  Process Death will throw these out of sync (see  Part 1  if you are unsure on how to cause this). This basic demonstration shows that rememberSavable...

Process Death - Part 1: Introduction and Overview

Image
Introduction This is part of a short series of posts about Process Death and how to mange it in the Modern Android Compose environment. Process Death - Part 1: Introduction and Overview An overview and a short code example to demonstrate Process Death - Part 2: Minimal Example Apps Examples of remember, not saving, crashing, and restoring values after Process Death Process Death - Part 3? - We'll see if this is needed (hopefully not) What is it, and when does it occur? Process Death means your app has been terminated by Android and no longer resides in memory, but it still appears in Recents* . If the app has implemented proper state saving, it should generally restore to a similar state when reopened. * The button that shows recent tasks — bottom left on my Samsung phone. The app remains listed in Recents and looks the same as always, so there is no easy way to know if Process Death has occurred. This makes testing slightly harder (see below for more information). Process Death oc...

Plain Kotlin Android Style Logging

Image
Plain Kotlin Android Style Logging Overview Android Studio Android Logging for any Kotlin project. Introduction In Android Studio Android projects, most people take advantage of the Android Logging Framework . However, if you write code externally or without that framework available, you would likely write all your output as println and then have to add the proper logging later. Moving the code back and forth would require changes and rewrites. To avoid this, I've put together a small logging class. The Code The code is pretty simple so here is everything: package com.xxxxxxxxxxxxx // https://source.android.com/docs/core/tests/debug/understanding-logging /* RFC 5424 Level RFC 5424 Severity RFC 5424 Description android.util.Log java.util.logging.Level 0 Emergency System is unusable Log.e / Log.wtf SEVERE 1 Alert Action must be taken immediately Log.e / Log.wtf SEVERE 2 Critical Critical conditions Log.e / Log.wtf SEVERE 3 Error Er...