This article is occasionally updated to summarize the problems that have plagued me for at least one day in mobile development.
1. Proxy networking:
In the network environment of China, I don't know how WAP is generated. I only know that many mobile phones support WAP by default. Proxy connections are never introduced in most of the books on the j2-based architecture. In this regard, I have taken many detours.
First, the standard mode is provided: If the proxy accesses the Internet, two points must be completed. 1. You should set the proxy server in your request url; 2. You must set the x-online-hos attribute.
GameConst. HTTP_CMWAP = "10.0.0.172: 80/" // Proxy Server
Conn = (HttpConnection) Connector. open ("http: //" + GameConst. HTTP_CMWAP + url );
Conn. setRequestProperty ("X-Online-Host", host );
Pay attention to the "url" in the above Code. It is the url after removing the host. For example, there is a full connection: Nobody (the bottom layer of the mobile phone helps you handle it ), some connections can be accessed normally (because the server corresponding to the connection helps you with url redirection). Of course, you cannot obtain valid information for many mobile phones or connections.
Pay attention to the "host" in the above Code. It is only a host, that is, a connection between hosts.
2. multithreading:
When you want to develop a project with a pure touch of 200 yuan, a high-definition camera, and a pure shanzhai mobile phone, you will know that the vendor is only a zombie. Of course, most of the users who buy such mobile phones do not download applications (do not bear the traffic or do not access the Internet ). However, your application has to adapt to these models. The simplest test I personally tested: Some mtk mobile phones cannot use multi-thread networking (here it means multithreading is supported, but if multiple threads are connected at the same time, there must be a thread with an IOException ). Therefore, in the current age when the number of mobile phones is still rampant, in order to adapt to all mobile phones and normal online applications, only three threads should appear in the program as allowed: one drawing thread (UI thread), one online thread, and one monitoring thread with network connection timeout. (Of course, there are some special requirements that may not be placed in these threads, but remember, opening one more thread means that your program may "lose" some low-end mobile phones ).
3. encoding:
Maybe we all know that Chinese characters must require UTF-8, GBK and Other encoding, but how many people know, inside the j2s, there may be some mobile phones do not support GBK? So, in the j2's program, or in the network request, all data involving Chinese, please use UTF-8, not for anything else, just because all mobile phones support UTF-8.
Author: Feng Xiaowei