Efficient Android development:

Source: Internet
Author: User

Efficient Android development:

Principles: 1. Do not do unnecessary things; 2. save memory usage as much as possible

  1. Avoid creating objects as much as possible
  2. Use your own method,

Such as string. indexof (), String. lastindexof (), multiplication of its own method

  1. Use virtualization is better than use interfaces.

In embedded development, calling through interface reference takes two times over virtual time, for example, map map1 = new hashmap () and hashmap MAP2 = new hashmap (); in embedded development, hashmap is recommended to create objects. Similarly, list = new arraylist () and arraylist = new arraylist () are also recommended.

  1. Static is better than virtual:

If you do not need to access the external object, make your method a static method and it will be called more quickly because it does not require a false function to direct the table.

  1. Avoid using the internal get and set methods as much as possible. We should use the get and set functions for external calls and directly call the internal functions.
  2. Buffer property call:

For (INT I = 0; I <this. mcount; I ++) {dumpitem (this. mitems [I])} should be written as follows:

Int COUNT = This. count; item [] items = This. mitems; For (INT I = 0; I <count; I ++) the {dumpitems [items [I]} principle is that you should not call a class method for the second time in the for statement.

  1. Declare final Variables
  2. Exercise caution when using the incremental for loop statement, mainly because an object is created here.
  3. Avoid Enumeration type,
  4. Use package space through inline classes

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.