A summary of performance optimization techniques for Android programming development _android

Source: Internet
Author: User

In this paper, the performance optimization techniques of Android programming development are summarized in detail. Share to everyone for your reference, specific as follows:

1.http with gzip compression, set connection timeout and response timeout

HTTP requests, according to business requirements, divided into whether can be cached and not cached, then in a network-free environment, still through the cached HttpResponse browsing part of the data to achieve offline reading.

2.listview Performance Optimization

1). Multiplexing Convertview

In Getitemview, determine if the Convertview is empty and, if not NULL, reusable. If the view in Couvertview needs to add Listerner, the code must be outside of the if (Convertview==null) {}.

2). Load Pictures Asynchronously

If Webimage is included in the item, it is best to load asynchronously

3). Do not show pictures when you slide quickly

When you quickly slide the list (scroll_state_fling), the picture in item or the view that needs to consume resources is not displayed, but in the other two states (Scroll_state_idle and Scroll_state_touch_ SCROLL), show those view

3. Using a thread pool

Divided into the core thread pool and the common thread pool, download pictures and other time-consuming tasks placed in the ordinary thread pool, to avoid time-consuming tasks blocking the thread pool, causing all asynchronous tasks must wait

4. Asynchronous tasks

Divided into core tasks and common tasks, only the core tasks in the system-level errors will be error, the asynchronous task UI operation needs to determine whether the original activity is active

5. Try to avoid using static member variables to refer to resource-consuming instances, such as context

6. Use WeakReference instead of strong references

A weak reference allows you to keep a reference to an object while allowing the GC to free up objects and reclaim memory if necessary. Consider using weak references for those who create cheap but memory-intensive objects that want to keep the object, and to use it when the application needs it, and you want the GC to recycle when necessary.

7. Super Big Fat Bitmap

Timely destruction (activity of the OnDestroy, will be bitmap recycled)

Set a certain sampling rate

Clever use of soft references

drawable corresponds to Resid resources, bitmap corresponding to other resources

8. Ensure that the memory occupied by cursor is released in time, rather than waiting for GC to process

And Android is obviously prone to programmers who manually close cursor off.

9. Threads are also an important source of memory leaks

The main reason why threads generate memory leaks is that the thread lifecycle is not controllable, and multithreading is used rationally.

10. If the ImageView picture is from the network, do asynchronous loading

11. Customize View

When customizing view in application development, the interactive part should never be written as a thread to constantly refresh the interface display, but rather to trigger the update of the interface according to the Touchlistener event.

I hope this article will help you with the Android program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.