Easy to transplant on various mobile phone platforms

Source: Internet
Author: User

Nowadays, mobile phones are becoming more and more popular, and more functions are available on mobile phones. Many people begin to develop applications on mobile phones, but mobile platforms are varied, if you want to enable the developed program to have a high commercial value, you must be able to adapt to the majority of mobile phone platforms. You must fully consider the portability of the program, I have been engaged in mobile app development for nearly three years and have experienced development on many mobile platforms, such as the s60 series and uiq series based on Symbian OS, the Pocket PC series and smartphone series based on Windows CE, such as MTK, Adi, and Philips, are deeply touched by the engineering design. Although they have experienced many failed lessons, they have gained a lot, here, we will summarize the porting design work over the past few years, hoping that it will be useful for those who are developing mobile applications. The following essentials should be taken into account in the design project:

1. Select a programming language that is easy to transplant. Currently, the mainstream languages used in mobile development are j2's and C languages. Because it has nothing to do with the platform, it has become the preferred development language, some features cannot be implemented on some mobile phone platforms, and some mobile phone platforms do not support the development of j2s, so I prefer to use C language. So far, C language is not supported yet. Although some platforms require C ++ for development, C ++ is still compatible with C language, here we will talk about how to develop a program that is easy to transplant in C language.

2. The design method of asynchronous functions should be designed in the programming architecture. When you call a function, you cannot immediately know the result when the function exits. You must obtain the message returned by the system to know the function call result. Such a function is an asynchronous function. Therefore, when calling platform-related functions, consider the possibility of asynchronous functions. You can design an event or message processing center and a timeout processing method to call platform-related functions, all are processed there to simplify the processing process.

3. encapsulate basic data types and basic standard functions in C language. Most platforms have a set of different basic data type definitions, which have the same functions but different C language functions. Especially for file operations, Function Method definitions in C language are basically not supported, however, the functions are the same, so they can be encapsulated by macro definition or redefinition.

4. It is best to have an independent memory management program. In some platforms, the implementation of memory allocation and release functions is relatively simple. Programs that generate more memory fragments may soon become unavailable, the maximum memory that can be applied for on some platforms may not meet the needs of the program. At this time, you need to design a memory management program.

5. The size of stack space should be considered during code design. The app stack space on the mobile platform is usually very small, and generally does not exceed 8 KB. function parameters, local variables, and recursive calls all occupy the stack space, therefore, many system functions on the mobile phone platform do not contain parameters. When the local variable in the function is an array variable, pay attention to the array length. If it is too long, Stack Overflow may occur, generally, there should be no more than 128 bytes. We should minimize the number of recursive levels of recursive functions or recursive functions. In addition, too deep function calls can easily cause stack overflow.

6. It is best not to have global variables. Currently, we only know that applications on the Symbian OS platform do not have global variables (but they can have global constants declared by static const). Of course, there are methods to use global variables on Symbian OS, however, it may be a little troublesome. It is best not to have global variables. If you really need global variables, the number of global variables should be as small as possible, and there should be a set of unified management methods for global variables.

7. bytes alignment should be taken into account. Most mobile phones are 4-byte alignment. Therefore, when designing the struct data type, the struct length should preferably be a multiple of 4 bytes, And the array length should also be a multiple of 4 bytes. For dynamically applied memory, it is recommended that you do not apply for memory smaller than 4 bytes; otherwise, the memory will be wasted.

8. Try to save memory usage. The available memory on the mobile phone platform is usually about several hundred kb. Of course, the memory of most smart phones (such as Symbian and Windows CE) can be several megabytes, there must be a good plan for memory usage. This issue must be taken into account in the design of the program architecture.

9. Take into account the byte sequence and character set type. Most mobile phones use the ucs2 character set, and the ucs2 character set has a high/low byte order problem. when processing the ucs2 character, if the processed character is lost, most of the reason is that the high and low byte order is wrong, but utf8 characters do not need to consider the byte order. Many systems use utf8 Characters Based on this consideration.

10. The number of cyclic operations should not be too large. Some systems will monitor cyclic operations. If the number of loops is too large and the calculation time is too long, the system will restart.

11. The duration of an uninterrupted processing process cannot be too long. Most low-end mobile phone operating systems are single-task or preemptible multitasking and do not support multithreading. If an uninterrupted processing process takes too long, the mobile phone will become like a dead machine because it cannot handle other events during this long process. In this way, the interaction of the program will be poor, it is best to divide a large process into small processes with shorter running time, and each small process is controlled by the UI Layer, so that other events can be responded and processed in a timely manner.

12. file operations cannot be performed too frequently. The system resources of the mobile phone platform are limited, which is far from comparable to that of the PC. Frequent file read/write operations may cause the system to be overwhelmed and minimize the number of file write operations.

13. Design of platform-related interfaces should be simplified as much as possible. The main workload of porting is to process the interface design. The simpler the interface design, the fewer interfaces, and the less workload the transplantation workload.

14. design the program debugging method. Debugging programs on the mobile phone platform is a very troublesome task. Some Mobile Platforms provide simulators for debugging, but at last they must go to the mobile phone for debugging. Therefore, the debugging method is very important, A set of independent debugging methods is required.

 

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.