Mobile Development 32 min read

Comprehensive Guide to Android App Performance Optimization: UI, Memory, Network, Power, and Code

This article presents a detailed technical guide on optimizing Android applications across UI smoothness, memory management, network efficiency, power consumption, and code structure, illustrating practical tools, metrics, and real‑world case studies from Ctrip’s large‑scale mobile platform.

Ctrip Technology
Ctrip Technology
Ctrip Technology
Comprehensive Guide to Android App Performance Optimization: UI, Memory, Network, Power, and Code

The document introduces the internal technical sharing platform of Ctrip engineers, aiming to promote knowledge exchange among development teams and improve both personal and team capabilities.

With the rapid evolution of mobile Internet and user expectations for flawless experiences, large‑scale apps (e.g., WeChat, Ctrip, Taobao) must continuously address performance issues such as UI lag, memory pressure, network latency, and battery drain.

UI Performance : Android apps target 60 fps (≈16 ms per frame). Skipped frames (SF) and smoothness (SM) are the key metrics. Tools like GPU Overdraw, GPU Rendering Mode, HierarchyViewer, and Traceview help identify layout complexity, overdraw, GC pauses, and method‑level bottlenecks. The article provides step‑by‑step usage instructions and sample adb shell dumpsys gfxinfo [package] commands.

Memory Optimization : Android’s Linux‑based memory management uses OOM levels and low‑memory killer thresholds. Strategies include avoiding large object allocations, reusing objects (StringBuilder, Bitmaps, system resources), preventing leaks, and handling onLowMemory/onTrimMemory callbacks. Tools such as Android Studio Memory Monitor, LeakCanary, and Traceview are demonstrated, with a code example of a typical memory‑leak pattern:

public final class MainActivity extends Activity { private SignleInstance mInstance; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // SingleInstance is a singleton class, holding MainActivity reference causing leak mDbManager = DbManager.getInstance(this); } }

Network Optimization : Both server‑side (dynamic IP, TCP instead of HTTP, protocol‑buffer + Gzip) and client‑side (connection reuse, request merging, CDN caching, Gzip compression) techniques are discussed. Converting Ctrip’s custom SOTP protocol to protobuf reduced payload size by 76 % and, together with TCP replacement, raised success rate above 99 % and cut average latency by ~30 %.

Power Optimization : Recommendations include preferring network location over GPS, minimizing network requests, using IntentService instead of Service, leveraging JobScheduler, and adapting behavior based on network type (Wi‑Fi vs 3G) to lower battery consumption.

Code Optimization : Replacing heavy HashMap structures with SparseArray or ArrayMap when keys are integers or data sets are small saves memory and improves lookup speed. Ctrip replaced 225 HashMap instances with SparseArray, achieving measurable performance gains.

Finally, the article summarizes that performance optimization is a broad, iterative discipline requiring a balance between feature delivery and resource usage; over‑optimization can introduce risk, so developers should apply these techniques judiciously.

performanceOptimizationUIAndroidNetworkMemorypower
Ctrip Technology
Written by

Ctrip Technology

Official Ctrip Technology account, sharing and discussing growth.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.