In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to optimize the performance of Android". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to optimize the performance of Android".
1.http uses gzip compression to set the connection timeout and response timeout
Http requests are divided into cacheable and non-cacheable requests according to business requirements, so in a network-free environment, part of the data is still browsed through cached httpresponse to achieve offline reading.
2.listview performance optimization
1)。 Reuse convertView
In getItemView, it is determined whether the convertView is empty, and if not, it can be reused. If the view in couvertview needs to add listerner, the code must be outside of if (convertView==null) {}.
2)。 Load pictures asynchronously
If webimage is included in item, then * load asynchronously
3)。 Do not display pictures when swiping
When swiping the list (SCROLL_STATE_FLING), the picture in item or getting the view that consumes resources may not be displayed, while in the other two states (SCROLL_STATE_IDLE and SCROLL_STATE_TOUCH_SCROLL), those view will be displayed.
3. Use thread pool
Divided into core thread pool and ordinary thread pool, time-consuming tasks such as downloading pictures are placed in the ordinary thread pool to prevent time-consuming tasks from blocking the thread pool, resulting in all asynchronous tasks having to wait
4. Asynchronous task
It is divided into core tasks and ordinary tasks. Only system-level errors in core tasks will report errors. Ui operations of asynchronous tasks need to determine whether the original activity is active.
5. Try to avoid static member variables referencing instances that consume too much resources, such as Context
6. Using WeakReference instead of strong references
Weak references allow you to maintain references to objects while allowing GC to free objects and reclaim memory if necessary. For objects that are cheap to create but consume a lot of memory, you want to keep the object and use it when the application needs it, and consider using weak references when you want GC to recycle if necessary.
7. Bitmap, a super fat man
Destroy in time (when Activity onDestroy, bitmap will be recycled)
Set a certain sampling rate
Ingenious use of soft quotation
Drawable corresponds to resid resources, and bitmap corresponds to other resources.
8. Ensure that the memory occupied by Cursor is released in a timely manner, rather than waiting for GC to deal with it
And Android obviously prefers programmers to drop Cursor close manually.
9. Threads are also an important source of memory leaks
The main reason for memory leakage of threads lies in the uncontrollable life cycle of threads and the rational use of multi-threads.
10. If the picture of ImageView is from the network, load it asynchronously
11. Custom View
When customizing View in application development, the interactive part must not be written as a thread to constantly refresh the interface display, but actively trigger interface updates according to TouchListener events.
Thank you for reading, the above is the content of "how to optimize the performance of Android", after the study of this article, I believe you have a deeper understanding of how to optimize the performance of Android, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.