Guides

How Android works inside

19 guides so far, newest first on each shelf. Each one starts from an API you already call and follows it into the source.

Android internals

How a part of Android really works, read from the source.

  • 18 min read

    How an Android Window Gets on Screen: WindowManager to SurfaceFlinger

    Follow one addView() call from your app to the screen: Window and PhoneWindow, WindowManager and WindowManagerGlobal, ViewRootImpl, the Binder call into WindowManagerService, the WindowState it makes, and the later relayout that creates the surface. Read from AOSP main, with a step-by-step lab.

    #android#windows#internals#binder#surfaceflinger

  • 21 min read

    How Apple, Samsung, Microsoft and Wacom Make Pens Feel Like Ink

    The ink series on one page: the stages a pen stroke goes through, and what Apple's, Microsoft's, Wacom's, Samsung's and Android's own documentation says about each. Only documented APIs and published specs count; what the pages don't say is marked as that, not guessed. With a lab to compare them stage by stage.

    #android#stylus#apple pencil#windows ink#wacom

  • 26 min read

    Saving and Sharing Strokes: Protobuf, Deltas and Last Writer Wins

    How a pen stroke becomes a few hundred bytes and back: Ink's quantised, delta-encoded protobuf, varints and ZigZag, gzip, and what saving loses. Then two devices editing one stroke: last writer wins, tombstones, what a clock can break, and a short look at CRDTs. With two labs: a save lab and a merge lab.

    #android#storage#protobuf#sync#internals

  • 26 min read

    Big Boards, Slow GPUs: Dirty Rectangles, Tiles and RenderNodes

    Why changing one stroke on a 4K board can repaint the whole board, what Android actually marks as dirty, and how to keep a change as small as the stroke: tile Views, bitmaps per tile and RenderNodes. With a lab that counts draw calls, pixels and uploads for four ways of holding finished strokes.

    #android#graphics#performance#panels#internals

  • 31 min read

    Many Hands on One Board: Ghost Points, Pointer IDs and Palms

    What happens when several students write on one large infrared panel at once: why two touches make four points, how a frame and then Android assign each hand an ID, what the system cancels before your app sees it, and what an app has to decide about pens, fingers, palms and pinches. With two labs: an infrared frame and the pointer IDs it produces.

    #android#input#touch#panels#internals

  • 28 min read

    The Eraser: Hit Testing, Spatial Indexes and Cutting Strokes

    How an eraser finds the strokes it touches and what it does to them: why testing the pen's samples loses strokes a fast pen crossed, how Jetpack Ink tests a stroke's triangles against a swept shape, why a document of thousands of strokes needs an index of its own (a grid, or an R-tree that never changes), and the two ways to cut a stroke in two. With a lab that counts the work.

    #android#ink#geometry#algorithms#internals

  • 35 min read

    Drawing with Low Latency: Wet to Dry

    How a pen stroke gets on screen without waiting for the next frame: unbuffered input, a front-buffered layer the display reads while you write to it, and the hard part, handing the finished stroke over to the normal View system with no blink and no double draw. Read from the androidx.graphics and Jetpack Ink sources, with two labs: pen to pixel, and the handoff.

    #android#ink#graphics#latency#internals

  • 31 min read

    From Points to a Stroke Mesh

    How a list of pen samples becomes the shape on the screen: a centreline (a Catmull-Rom spline, or the time-window average Ink uses), a width from pressure or speed, two outlines offset from it, and the triangles between them; why a turn tighter than the line is wide folds the mesh; Ramer-Douglas-Peucker simplification; and how Jetpack Ink's PartitionedMesh holds and draws the result. With a lab that builds the mesh from one noisy stroke.

    #android#ink#graphics#geometry#internals

  • 27 min read

    Smoothing and Predicting the Pen

    Why raw pen samples need work and what it costs: noise, and a line that trails the pen. Moving average, exponential smoothing and the One Euro filter, with the lag each one adds; the Kalman filter from AndroidX's motion prediction library, read from its source; why constant-velocity prediction fails on noise and corners; Android's two predictors, the AndroidX Kalman library and the API 34 platform MotionPredictor, and how the library picks one; and how to draw a predicted tail without saving it. With a lab that scores every filter and predictor against a known path.

    #android#ink#input#kalman#internals

  • 22 min read

    Reading a MotionEvent: Pointers, History and Axes

    What a MotionEvent holds and how to read it: actions and the pointer index they carry, why a pointer's index changes but its ID doesn't, the history bundled into a move, every axis (position, pressure, size, orientation, tilt, distance) and which devices report it, tools, buttons, hover and cancel, and what Compose's PointerInputChange keeps and drops. Read from the AOSP and AndroidX source, with a pointer table to step through and a pad that shows your own device's readings.

    #android#ink#input#motionevent#internals

  • 20 min read

    From Glass to Your App: How a Touch Reaches Android

    What happens between a finger or pen on the glass and your onTouchEvent(): capacitive grids, EMR and active pens, infrared frames, the Linux multi-touch protocol, EventHub, InputReader and palm rejection, InputDispatcher and the 5-second ANR, the socket every window gets, and how the app batches and resamples touch to the frame. Read from the AOSP source, with a resampling lab you can break.

    #android#ink#input#motionevent#internals

  • 14 min read

    Looper, epoll and Vsync: The Heartbeat of an Android Frame

    How the main thread waits, wakes and draws: Handler and MessageQueue, the native Looper sleeping in epoll_wait, the eventfd that wakes it, the input and vsync file descriptors it watches, Choreographer's frame and its five steps, and the sync barrier that lets a frame jump the queue. Read from the AOSP source, with a frame timeline you can break.

    #android#ink#looper#choreographer#internals

  • 14 min read

    Canvas, Paint and Path: How Android Draws a Stroke

    The three objects behind every line an Android app draws, and the settings that decide how it looks and what it costs: style, width and hairlines, caps, joins and the miter limit, curves, path effects, blend modes and erasing, what the GPU does with your paths, and the same toolkit in Compose.

    #android#ink#canvas#paint#compose

  • 15 min read

    Why Naive Drawing Feels Bad on Android

    Draw a line to every touch event and you get lag, corners, wobble, palm marks and an app that slows as the drawing grows. The twelve ways naive ink fails, why each one happens, and what fixes it. The first guide in the ink series, with a live ink lab.

    #android#ink#motionevent#canvas#internals

  • 5 min read

    Why I Read the Source of the Android Libraries I Use

    The APIs tell you what to call. The source tells you what will happen when the user rotates the phone, reboots it or swipes your app away. How this series is laid out, and what reading internals teaches.

    #android#internals#learning

  • 14 min read

    How WorkManager Actually Runs Your Work

    From enqueue() to doWork() and back: the database row, the two schedulers, retries, periodic work, reboots and force-stops, read from the AndroidX source. With a simulator, the class map, edge cases and cross questions.

    #android#workmanager#background work#internals

  • 10 min read

    How a ViewModel Survives Rotation, in Activities and in Compose

    What a ViewModel is, who owns it, how the store is handed from the old Activity to the new one, when onCleared() really runs, and how Fragments, Navigation and Compose find the right instance. Read from the AndroidX source.

    #android#viewmodel#jetpack compose#internals

  • 12 min read

    Process Death vs Activity Recreation, and How Saved State Really Works

    Why your screen forgets everything after an hour in the background, what survives which event, and how SavedStateHandle, rememberSaveable, Bundle, Parcelable, Serializable and Kotlin Serialization fit together. Read from the AndroidX source and Google's guidance.

    #android#saved state#process death#parcelable#internals

  • 14 min read

    Android Launch Modes: Where Will My Activity Open?

    One decision tree for standard, singleTop, singleTask and singleInstance, then the platform code that runs it: which task an Activity lands in, and whether you get a new instance or onNewIntent(). With the class map, edge cases and cross questions.

    #android#activities#tasks & back stack#launch modes#internals

Want them in order? Follow the roadmap.