Building the Android application for a dedicated measurement instrument was not primarily a UI project. The screens were only the visible layer of a system that had to receive substantial measurement data from a separately developed native and hardware stack, remain correct through Android lifecycle transitions, preserve results across releases, and stay maintainable after the original development team changed. Those constraints shaped the architecture far more than any preference for a particular Android framework. On the Android side, I was responsible for the application architecture, the Java/JNI/native boundary, Binder and AIDL control, shared-memory result handling, synchronization, lifecycle coordination, conversion of native results into UI-facing models, navigation and state restoration, data compatibility, persistence, removable-storage control, and update orchestration. The FPGA logic, PCIe hardware, kernel driver, and internal hardware-control algorithms belonged to other engineers. My responsibility was to give that separately developed native and hardware system a safe, efficient, and maintainable boundary with Android. This article focuses on one part of that work: why commands traveled through Binder while measurement data traveled through shared memory, and how the same design principles extended into lifecycle management, navigation, persistence, and long-term maintenance.
The Real Requirement Was Not “Build an Android UI”
The customer did not need Android for its own sake. Android was the presentation and interaction layer of a dedicated instrument. The product needed to:
- display substantial native measurement results without making data transfer a bottleneck;
- prevent Fragment recreation or teardown from corrupting command processing;
- keep navigation and state restoration consistent across many screens;
- preserve settings and state even when power could disappear unexpectedly;
- remain usable across software upgrades and, when necessary, downgrades;
- allow future maintainers with strong product and hardware knowledge, but limited Android experience, to change screens and settings;
- remain supportable as dedicated hardware that would be much harder to correct after shipment than a web or consumer mobile application. That changed the design question. Instead of asking, “Which Android architecture should I use?”, I had to ask:
- Where should each piece of state live?
- Which operations are commands, and which are data transport?
- What must remain valid when a Fragment disappears?
- What happens if power disappears during normal operation?
- What happens when persisted data outlives the software version that created it?
- How much Android-specific knowledge should an ordinary screen implementation require?
- Who will maintain this product later? The answers led to a small set of centralized mechanisms: a control plane, a separate measurement data plane, lifecycle-aware command dispatch, a screen-context navigation model, version-aware persistence, and a constrained configuration workflow for maintainers.
The Native/Android Boundary
The native system handled measurement and hardware-facing behavior. Android had to issue commands, receive notifications, obtain results, and convert those results into models that screens could consume safely. Exposing native structures or concurrency directly to individual Fragments would have made every screen responsible for too much:
- cross-process communication;
- native resource lifetime;
- synchronization;
- partial result updates;
- Android lifecycle state;
- conversion from native representation to display semantics. It would also have tightly coupled the UI to implementation details owned by the native team. I treated the boundary as an architectural component rather than a collection of JNI calls. Control operations were serialized on the Android side. Measurement state was read as snapshots. Native-oriented layouts were converted into Java result objects before reaching ordinary UI code. This gave each side a clearer contract. The native and hardware layer could retain its own internal design. Android did not need to know how RF, power, PCIe, or other hardware-control mechanisms were implemented internally. It needed stable commands, status, and result layouts. Likewise, UI code did not need to know whether a value originated in a native thread, a service callback, or a shared-memory region. It received an Android-side representation with explicit meaning. That separation was as much about ownership and failure containment as it was about language interoperability.
Why Control and Bulk Data Took Different Paths
The system used six AIDL interfaces for control and callbacks. Binder was a good fit for operations such as starting or stopping work, changing settings, requesting state transitions, and notifying Android that something had changed. It was not the path I wanted for every measurement payload. The results included large arrays and collections such as constellation data, spectrum data, delay profiles, channel lists, and service lists. Returning those repeatedly through Binder would have introduced more serialization, allocation, copying, and transaction pressure. So I separated two kinds of communication. The control plane used Binder and AIDL:
- issue a command;
- request an operation;
- receive a notification;
- obtain the file descriptors and metadata needed to access results. The data plane used ashmem-backed shared memory:
- native and Android mapped agreed result regions;
- Binder carried control information instead of repeatedly carrying measurement data;
- Android read result snapshots and converted them into UI-facing Java models. The application defined 23 shared-memory regions for different categories of state and results. This was not one undifferentiated buffer. Those layouts formed an interface that had to remain consistent across Java and C. The benefit was not that shared memory was inherently more sophisticated. It was that it matched the characteristics of the data. Commands were discrete operations. Measurement results were larger and changed frequently. Making both use the same transport would have optimized the architecture for conceptual uniformity rather than product behavior. My early development experience was on systems where CPU time, memory, I/O, and copying could not be treated as invisible resources. The lesson I carried forward was not to preserve old techniques. It was to keep asking where data moves, who owns it, how many times it is copied, and how long the underlying resource must remain valid. The same reasoning applied here. Shared memory also introduced costs. Java and C had to agree on layouts and constants. Readers needed consistent snapshots rather than arbitrary views of an update in progress. Calls and result access required synchronization. Changes to the shared representation had to be treated as interface changes. The architecture did not eliminate complexity. It placed complexity at a boundary where it could be reviewed and controlled instead of redistributing it across every screen.
Keeping Android Lifecycle Out of Ordinary Feature Code
Efficient data transport would not have been enough if commands could still reach a screen after it had stopped or been destroyed. This application had hardware-key input, asynchronous native results, dialogs, background operations, and frequent Fragment replacement. A conventional implementation could easily have left each Fragment responsible for registering callbacks, holding references, checking its own lifecycle, and cleaning everything up correctly. That model scales poorly. It also assumes every future maintainer understands the less obvious consequences of Android lifecycle transitions. I built a lifecycle-aware command infrastructure around annotated command endpoints. Feature code marked callable fields or methods with @CommandFunction. A central command manager registered those endpoints together with a LifecycleOwner, observed lifecycle transitions, built the command map, and removed destroyed owners. The invoker rejected a call unless its owner was in an eligible started or resumed state. A screen could therefore express, “This is the action for this command,” without reimplementing the same lifecycle checks and cleanup logic. The application eventually used command endpoints across activity, screen, measurement, settings, update, Bluetooth, and data-logging features. Centralizing their lifecycle rules made behavior more consistent across those areas. There was a trade-off. Annotation scanning, reflection, and string-based command names are less discoverable than direct method calls. They require naming discipline, validation, and documentation. A central dispatcher can also become difficult to understand if it accumulates unrelated responsibilities. For this product, that cost was acceptable because it addressed a more important risk: stale Android objects receiving real device commands. The goal was not to make the Android lifecycle disappear. It was to keep framework-specific safety rules in infrastructure instead of forcing every feature author to reconstruct them.
Making Navigation Data-Driven
Navigation had a similar problem. This was not a typical mobile application with a mostly linear flow and standard back-stack behavior. It needed hardware-key navigation, conditional transitions, top/back/replace behavior, popups, state restoration, and differences among product configurations. Hard-wired Fragment-to-Fragment calls would have created a dense dependency graph. A route change would have required Android source changes, and each Fragment would have needed to understand both its own behavior and the surrounding screen structure. Instead, I represented navigation using screen definitions and linked ScreenContext objects. A screen context carried the current screen definition, its parent context, result data, and last-state data. A central screen manager constructed the required Fragment type and handled navigation operations such as next, replace, jump, top, and back. Configured actions could also contain conditional branches. Fragments therefore did not need direct references to destination Fragment classes. Navigation targets lived in screen configuration, while Fragment creation and replacement remained centralized. This also gave the application one place to coordinate navigation with activity state. State restoration required additional care. Persisted values can outlive the menu or configuration that gave them meaning. The release history contains a concrete case where changing the number of menu entries made previously stored screen state invalid. The eventual handling validates restored values and falls back to a safe screen when the previous context can no longer be reconstructed. That is a useful reminder: saved UI state is not automatically trustworthy. In a configurable product, persisted state is versioned input.
Persistence Had to Survive More Than App Restarts
The same principle applied to the database. This was dedicated hardware. Power could disappear at an arbitrary point, and software installed in the field could move not only forward to a newer version but also backward to an older one. A conventional forward-only migration mindset was not enough. The screen configuration, packaged JSON, and persisted Room data were therefore treated as parts of the same contract. The application contained hundreds of settings definitions. Each screen-oriented settings definition had an ID, and the corresponding Room record used that ID as its primary key. The record also carried version and checksum information, while the settings document itself remained JSON. This was a deliberate choice. A deeply normalized relational model would have made individual fields easier to query, but querying arbitrary settings combinations was not the primary requirement. The important requirement was that the unit created by the configuration system remained the same unit that could be loaded, replaced, validated, recovered, and understood later. The flow was effectively: Excel → JSON → screen definition → Room record Keeping those units aligned simplified the lifecycle of the data. Each software version shipped with its own canonical settings JSON. During initialization, Android could compare persisted records against those packaged definitions using version and checksum information. When compatible changes were introduced, existing user choices could be merged into the newer definition. When a device had to return to an older software version, the priority was different: the older application had to receive data it could actually understand. Settings introduced by a newer schema could therefore be replaced by the older version’s readable definition rather than leaving behind data that might be structurally valid but semantically unusable. Upgrade compatibility was not enough. The persistence design also had to consider downgrade recovery. That trade-off matters on field hardware, where reverting software can be part of recovery. It also changes how I think about database correctness. Room transactions and migration code are useful guarantees, but on hardware that can lose power without warning, I do not want to rely only on what should happen. Abrupt physical power removal was deliberately tested at arbitrary operating points, followed by restart, to verify that the application and persisted data remained usable. The exact interruption matrix and quantitative test record are no longer available, so I cannot claim a measured failure rate. What matters to me is the engineering habit: when sudden power loss is part of the product environment, physically remove the power and test the recovery path. The persistence design sacrificed some relational elegance. Keeping a JSON document inside a Room record makes field-level SQL querying less convenient. It places more responsibility on schema validation and application-level interpretation. But it gave this product something more important: a bounded persistence unit aligned with the screen model, deterministic defaults for every software version, explicit upgrade and downgrade behavior, and a practical recovery path after unexpected power loss. Again, the architecture was not chosen because it looked conventional. It was chosen because it matched how the product would actually fail and how it would actually be maintained.
Designing for the People Who Would Maintain It Later
The surrounding organization was oriented toward hardware and C development. The likely future maintainers understood the instrument, its terminology, and its hardware behavior, but they could not be expected to reconstruct a large Android Fragment architecture every time a routine screen change was needed. That organizational reality became a technical requirement. I created an Excel-based authoring tool that exported screen and setting definitions as JSON. The Android application consumed those files through generic parsers, reusable screen types, shared fragments, configured actions, and the command and navigation infrastructure described above. Excel was not chosen because it was a fashionable application-development tool. It was chosen because it was accessible to the people expected to maintain the product. The important part was not simply “using JSON.” The design covered both sides of the maintenance path:
- a constrained authoring environment familiar to maintainers;
- a generated, machine-readable format;
- an Android runtime designed to interpret that format consistently;
- a persistence model aligned with the same configuration units. This moved many routine changes from bespoke Fragment code into structured product data. It also moved some risks. Configuration schemas required discipline. The editor needed validation. Parsers had to preserve compatibility. Invalid IDs, action names, or parameter combinations could otherwise become runtime failures that a compiler might have caught in conventional code. A data-driven UI does not remove engineering work. It changes who can perform common changes and where mistakes are detected. For this organization, that was the right trade-off.
What This Architecture Cost
The architecture had deliberate costs. Shared memory required coordinated Java/C layouts, synchronization, and clear snapshot semantics. The lifecycle-aware command system used reflection and names instead of relying only on direct, compile-time-visible calls. The navigation layer was a custom state machine rather than a thin wrapper around Android’s default back stack. The Excel-to-JSON workflow introduced a schema, generator, parser, compatibility obligation, and additional validation surface. The Room design retained JSON documents rather than normalizing every setting into relational columns, sacrificing some query flexibility in exchange for compatibility and recovery properties. Central infrastructure also creates concentration risk. If too much behavior accumulates in one manager, a local change can have broad effects. Those components therefore needed narrow responsibilities and careful review. I accepted those costs because they matched the product’s actual risks. Data-copy pressure, stale lifecycle owners, direct screen coupling, incompatible persisted state, power-loss recovery, and dependence on scarce Android expertise would have been harder to manage over the lifetime of the product. The design was not about minimizing code. It was about placing complexity where the team could control it. There was another cost that became clearer as the application grew. ViewModels, repositories, native-to-UI mappers, Room mappings, command dispatch, and event notifications each solved a real local problem, but some end-to-end paths became difficult to trace. A value could cross several abstractions before reaching the screen, and each hop could add allocation, copying, dispatch, or synchronization overhead. On fixed hardware, that overhead is not free. In some areas I accepted a small amount of performance loss in exchange for lifecycle safety, maintainability, and clearer ownership. That was often the right trade-off, but the accumulated complexity should still have been reviewed more aggressively as the system evolved. The important lesson is that individually reasonable abstractions can still produce a system that is too complicated when viewed end to end.
What I Would Simplify Today
I would keep the major architectural boundaries, but I would simplify some of the intermediate paths that accumulated over time. In particular, I would review chains involving ViewModels, repositories, ORM or Room mappings, native-to-UI conversion layers, and event notifications. Where several layers merely pass the same state forward without adding ownership, validation, lifecycle safety, or a meaningful domain transformation, I would collapse them. I would also make end-to-end data flow easier to inspect. A developer should be able to answer, with little effort: where did this value originate, where was it transformed, who owns it now, and what causes the UI to update? I would not remove abstractions simply to make the code shorter. Some of them protect important boundaries. The goal would be to distinguish abstractions that still pay for themselves from those that remain only because they were locally convenient when added. The mistake was not abstraction itself. It was allowing too many locally reasonable abstractions to accumulate without periodically simplifying the complete path.
What I Would Keep Today
I would keep the separation between control and data transport. The exact shared-memory API might change with the Android platform and deployment environment, but commands and high-volume state still have different characteristics. I would also keep lifecycle eligibility as an infrastructure concern. Whether implemented with annotations, generated bindings, or another mechanism, a destroyed UI owner should not remain a valid command target. The screen-context model also remains appropriate for a fixed-function embedded product whose navigation semantics differ from those of an ordinary mobile application. I would keep the alignment between configuration and persistence as well. A modern implementation might use more strongly typed generated schemas and more build-time validation, but I would still want a deterministic per-version source of truth and an explicit policy for both upgrade and downgrade. For the configuration system, I would keep the domain-oriented authoring path while adding stronger validation earlier in the process. Most importantly, I would keep the decision process: Start with the customer’s operating environment, the product’s expensive failure modes, and the capabilities of the people who will maintain it. Framework selection comes after that.
Lessons
Several lessons from this system apply beyond Embedded Android:
- Treat a Java/native boundary as a product interface, not a collection of convenient function calls.
- Commands and bulk data do not need to use the same transport.
- Shared memory reduces copying only when ownership, synchronization, layout compatibility, and snapshot rules are explicit.
- Convert native results into stable UI models before those representations spread through feature code.
- A lock or resource owner must live as long as the resource it protects, not merely as long as the current Fragment.
- Centralize lifecycle rules when many features would otherwise repeat them inconsistently.
- Direct screen dependencies become expensive when navigation is configurable.
- Persisted state must be validated against the current schema and configuration.
- Database migration on field hardware may need to work in both directions.
- If sudden power loss is a real operating condition, test sudden power loss on real hardware.
- The most normalized database is not automatically the best persistence model for every product.
- Every abstraction has a runtime and cognitive cost; review the complete path, not only each layer in isolation.
- If several layers only forward the same state, simplify them unless they provide a real boundary or guarantee.
- Maintenance tools should fit the people who will actually use them.
- The best architecture is not the one with the most modern vocabulary. It is the one whose trade-offs match the product.
Closing
In this project, Binder, AIDL, JNI, shared memory, Room, annotations, JSON, and Fragments were implementation tools. None of them was the objective. The objective was to let Android present data from a separately developed native and hardware system without making the UI responsible for native concurrency, to prevent lifecycle transitions from turning into command failures, to keep persisted state recoverable across power loss and software versions, and to leave behind a product that people without deep Android expertise could still maintain. That is how I approach systems work: Start with what the customer needs, identify what the product cannot afford to get wrong, and design for the people who will inherit it.