A summary of some of the experiences in the Android development process

Source: Internet
Author: User

This article is a summary of common problems encountered during the Android APP development process, and the summary will continue to be optimized. Follow-up development will encounter a variety of problems, these issues will be added in the appropriate and continuous.

The problems I will encounter fall into two major categories, non-technical and technical issues.

One, non-technical issues.

Non-technical problems are generally the project management issues, focusing on the coordination and communication issues in the project development process.

1. Implementation of the project.

2. Progress of the project.

3. Tracking of the project.

4. Project completion summary and evaluation.

Second, the technical level of the problem.

1. Code specification issues.

This issue has been in the company's internal technology sharing group I have suggested that I personally think the code standard evaluation criteria is: Let two people to write a piece of code (the same can be different), let the third party to see, he can't tell the two pieces of code is written by a different two people.

2. Guarantee of the quality of the code.

From three aspects:

(1) Accurate judgment and estimation of the actual production situation in the future. Judging the large-scale use situation, can resist high concurrency or large traffic pressure.

(2) When writing code, the programmer has strict requirements and high-level pursuit of the code quality. For example, whether the unit test can guarantee hundred percent coverage, whether the boundary conditions are considered completely and so on.

(3) Whether there is a continuous improvement in the technical capacity of the internal demand, whether it is in-depth study of related technologies, and expand their technical horizons.

On the above three aspects of immediate attention although not to achieve the effect of the shadow, but in the long run, if you can persevere, imperceptible practice, I believe that the personal technical level of the promotion effect is very significant.

Three, the following simple examples of some technical aspects of the problem:

Android development process encountered problems are more trivial, generally through the search engine, reference to other people's solutions, can be better resolved.

So here's the focus on the Android APP performance optimization problem.

1. Reduce Execution time
This part includes: Cache, data storage optimization, algorithm optimization, JNI, logic optimization, optimization of demand optimization methods.
(1). cache
The cache mainly includes object cache, IO cache, network cache, DB cache, the object cache can reduce the allocation of memory, the IO cache reduces the number of disk reads and writes, the network cache reduces network transmission, and the DB cache is less than the number of database accesses.
In memory, file, database, network read and write speed, memory is optimal, and the speed of the order of magnitude difference, so as far as possible will need to frequent access or access to a large consumption of data stored in the cache.

Caching is often used in Android:
Message caching
The message before the handler.obtainmessage is reused as follows:

Handler.sendmessage (handler.obtainmessage (0, object));

(2). Data storage optimization
Includes the data type, the choice of the structure.
A. Data type selection
string concatenation uses StringBuilder instead of string, and StringBuilder instead of StringBuffer in the case of non-concurrency. If you have a general understanding of the length of the string, such as about 100 characters, you can specify the initial size directly from new StringBuilder (128), reducing the redistribution when space is not enough.
A 64-bit type such as a long double is slower than 32 bits, such as int
More useful for system garbage collection using SoftReference, WeakReference, and relatively normal strong applications
Final type storage is more efficient in constant area reading
Localbroadcastmanager replaces common broadcastreceiver for higher efficiency and safety

B. Data structure selection
Common data structures are selected such as:
ArrayList and LinkedList Choice, ArrayList based on index value faster, LinkedList more memory, random insert delete faster, more efficient expansion. Generally recommended ArrayList.
ArrayList, HashMap, Linkedhashmap, HashSet choice, hash series data structure query speed is better, ArrayList store ordered elements, HashMap for key-value data structure, Linkedhashmap can remember that the hashmap,hashset of the join order does not allow repeating elements.
HashMap, Weakhashmap selection, weakhashmap elements can be automatically reclaimed by the system garbage collector at the appropriate time, so it is suitable for use in memory-intensive type. The choice of Collections.synchronizedmap and Concurrenthashmap, the Concurrenthashmap is the subdivision lock, the lock granularity is smaller, the concurrency performance is better. Collections.synchronizedmap is an object lock, it is more convenient to add function to lock control.

Android also offers some of the more powerful data types, such as Sparsearray, Sparsebooleanarray, Sparseintarray, and Pair.
The data structure of the sparse series is a special process for the case of the key int, using binary lookup and simple array storage, plus the overhead of not requiring a generic conversion, and better performance than the map. But I don't quite understand why the default capacity size is 10, is it statistical, or now memory optimization does not need to consider these things, write 16 will die, or recommend that you set the initial value according to their possible capacity.

(3). Algorithm optimization
This topic is bigger, need concrete problem concrete analysis, try not to use O (n*n) time complexity above algorithm, necessary time free space change time. The query considers the hash and the two points, try not to recursion.

Improper use of recursion, easy to trigger stack overflow problem.

(4). JNI
Most Android applications are developed in Java, requiring the Dalvik JIT compiler to run Java bytecode into cost code, while local code can be directly executed directly by Device Manager, saving intermediate steps, so execution is faster. However, it is important to note that switching from Java to local space requires overhead, while the JIT compiler can generate optimized native code, so bad native code does not necessarily perform better.

(5). Logical optimization
This is different from the algorithm, mainly to clarify the program logic, reduce unnecessary operations.

(6). Demand optimization
This will not say, for SB's demand may bring performance problems, can only be said as a qualified programmer can not just performers, to learn to say no. But do not take this interface perfunctory product Manager Oh.

2, asynchronous, using multithreading to improve TPS
Take advantage of multi-core CPUs to leverage threading to solve intensive computing, IO, and network operations.
In Android applications due to system ANR limitations, it is possible to cause the mainline blocks until those operation to be placed in another worker thread. In a worker thread, you can interact through handler and the main thread.

4. Network optimization
The following are some of the guidelines that the client and server sides of network optimization need to follow as much as possible:
A. Pictures must be cached, it is best to do pictures according to the model to do a picture adaptation
B. All HTTP requests must be added Httptimeout

C. Turn on gzip compression
D. API interface data is returned in JSON format instead of XML or HTML
E. Determine if the request results are cached based on the Cache-control and expires domains in the HTTP header information.

F. Determine if the connection of the network request is keep-alive
G. Reduce the number of network requests, the server side do the appropriate request consolidation.
H. Reducing the number of redirects
I. API interface Server-side response time not exceeding 100ms

A summary of some of the experiences in the Android development process

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.