当我试图减少我的 Android 应用程序并对其进行优化时,我会寻找所有可能的方法来做到这一点。这是我发现的:
- Avoid Creating Unnecessary Objects
- Prefer Static Over Virtual
- Use Static Final For Constants
- Avoid Internal Getters/Setters Use
- Enhanced For Loop Syntax, etc.
- Use local variables instead of public class fields when possible.
- Use the final keyword to hint that a value is constant
- Use the final keyword for class and method definitions, etc.
C.而不是使用 view.setOnClickListener(new View.OnClickListener...)
,使用
view.setOnClickListener(this)
,通过将监听器附加到 Activity 或 fragment 。
D. http://www.vogella.com/tutorials/AndroidApplicationOptimization/article.html
E. http://developer.sonymobile.com/2012/01/31/tips-for-reducing-apk-file-size/
- Remove debug information.
F. http://hsc.com/Blog/Best-Practices-For-Memory-Optimization-on-Android-1
- Use Optimized Datacontainers
- Use Proguard And Zipalign
G. http://ernelljava.blogspot.se/2012/04/do-not-create-objects.html
- Do not overuse String, use StringBuilder for working with String.
H. https://github.com/futurice/android-best-practices
是否有任何其他技巧可以帮助我优化我的应用程序?
最佳答案
检查以下几点以获得更好的编码和优化,
(-) 保持你的编码干净,并且是小部分,
(-) 不要写长的单个函数,把它分成小函数,
(-) 永远不要在主线程上调用任何网络功能,为此始终使用异步任务。
(-) 任何资源在使用完成后,迅速释放它,不要一直使用它,以避免出现死锁情况。
关于android - 如何提高 Android 应用程序的整体性能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31911386/