优化Android性能涉及保持UI线程响应、有效的内存使用(避免泄漏)、流畅的渲染、高效的列表和性能分析以找到瓶颈。性能直接影响用户体验,对于Android设备的多样化范围很重要。
保持UI(主)线程响应
✓ NEVER block the main thread → do network/DB/heavy work OFF it (coroutines + Dispatchers.IO)
→ blocking causes jank or ANR ("App Not Responding") — a top issue
✓ Keep work in onCreate / onBind / on the main thread minimal and fast
内存和泄漏
✓ Avoid MEMORY LEAKS — a common Android problem:
→ don't hold Activity/Context references beyond their lifecycle (a classic leak)
→ unregister listeners/observers; use lifecycle-aware components; cancel coroutines
→ use tools like LeakCanary to detect leaks
✓ Manage bitmaps/images carefully (large memory); use image libraries (Glide, Coil)
