Key Lessons from Building Android Apps: Architecture, Maintainability, and Security
After transitioning from JavaEE to Android development, the author shares practical insights on designing robust mobile app architecture, covering maintainability, extensibility, security, onboarding ease, documentation, packaging, and the trade‑offs between MVC and MVP, while offering guidance on framework selection and effective encapsulation.
I have been developing Android apps for over two years after moving from JavaEE, working on several company projects, most of which I initially built alone, gaining experience in architectural design.
What Is Architecture
Software architecture is more than just stacking frameworks; it aims to improve maintainability, extensibility, security, and onboarding (the ability for a newcomer to quickly understand and modify the project).
Maintainability
A maintainable codebase allows fast issue location, easy modifications, and minimizes the introduction of new bugs.
Code standards : Without consistent conventions, code becomes hard to maintain even for its original author.
Framework stability : Prefer mature, well‑tested frameworks over brand‑new ones to avoid hidden instability.
Encapsulation : Wrap common utilities behind a single entry point to reduce duplicated changes and avoid pitfalls such as context‑related memory leaks.
Coupling : Reduce unnecessary coupling; over‑engineering to eliminate every coupling can waste performance.
Extensibility
Extensibility measures how easily new features can be added.
Abstract interfaces : Define interfaces (e.g., click listeners) to decouple implementations.
Element reuse : Extract common UI components for reuse across modules.
Single responsibility : Keep classes focused on a single purpose; refactor when responsibilities grow.
Replaceability : Design components so that layouts or implementations can be swapped without rewriting adapters.
Coupling : Similar to maintainability, avoid excessive interdependence.
Security
Security includes both data protection and operational safety.
Data security : Use HTTPS, checksum verification, and multi‑file logging to detect tampering.
Operational safety : Prevent rapid repeated actions (e.g., button spamming) by disabling controls during network requests or activity transitions.
Onboarding (Cut‑inability)
Good onboarding relies on solid documentation, clear comments, and logical package organization.
Documentation : Maintain coding standards, package naming conventions, and API docs.
Comments : Annotate classes and methods, indicating owners and complex logic.
Package naming : Separate packages by feature (e.g., UI, network, data) and then by module (e.g., login, user).
wang.raye.demo |-activity | |-user | |-login |-fragment | |--user | |--login
MVC vs MVP
Both patterns are used in Android; MVC maps XML to View, Activity/Fragment to Controller, and data classes to Model, but often the Activity handles view logic, limiting true separation.
MVC pros : Quick development, easy to understand.
MVC cons : Complex UI logic becomes hard to maintain.
MVP pros : Easier to modify business logic, reduces bugs, supports collaborative development.
MVP cons : Slower development speed.
Thus, MVC suits simple, data‑display apps, while MVP fits complex, large‑scale projects.
Framework Selection and Usage
Choosing a framework requires evaluating stability, extensibility, and encapsulation.
Stability : Prefer frameworks that have proven reliability.
Extensibility : Ensure the framework can grow with new features or be extended when needed.
Encapsulation : Wrap framework calls behind a unified entry point so that swapping frameworks later only requires changes in one place.
After selecting a framework, avoid using it directly; instead, create a thin abstraction layer. Some lightweight libraries (e.g., ButterKnife) may not need extra wrapping, but larger ones (e.g., OkHttp, UniversalImageLoader) should be encapsulated.
The main benefit of proper encapsulation is that replacing a framework becomes a simple matter of updating the unified entry point.
Conclusion
These reflections on Android app architecture provide guidance on what to consider when building a robust system; they are not a step‑by‑step tutorial but a collection of principles to help you design maintainable, extensible, and secure applications.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
