简体   繁体   中英

What are the most important optimizations in Java code on Android?


I am just starting out programming on Android.

What is the most computationally expensive Java constructs to avoid when programming an Android App?

Of cause every algorithm costs instructions, but what about use of Method calls, Object references, Interfaces, Collections and such? What do I need to avoid, and what is "cheap" when I'm programming for speed?

You can find official guidelines here: http://developer.android.com/guide/practices/design/performance.html

You should also read http://developer.android.com/guide/practices/design/responsiveness.html and http://developer.android.com/guide/practices/design/seamlessness.html

There are some specific GUI optimizations (like ViewHolder pattern for ListAdapters) but start writing your app first, then fix things which are too slow. And remember: do not guess, use included profiler (tool TraceView and Debug class) to find out what exactly needs to be improved.

1) Write clean code. Poor code will hurt performance more than any micro optimization.

2) Understand Big Oh runtime, and make intelligent use of data structures.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM