The tragedy of hospitalization, idle and boring. Sort out the notes written in previous projects.
Because of the versatility of the project, the old boss gave advice to make a jar package similar to the package.
Because there is no time, the boss is too overestimating me =.
Here are just a few general technologies
General Technology 1: network detection after the App enters.
The code is simple.
Import android. content. Context;
Import android.net. ConnectivityManager;
Import android.net. NetworkInfo;
/**
* Network monitoring tools
*
* @ Author Nono
*
*/
Public class NetUtil {
Public static boolean checkNet (Context context ){
Try {
// Obtain the connection management object
ConnectivityManager connectivity = (ConnectivityManager) context
. GetSystemService (Context. CONNECTIVITY_SERVICE );
If (connectivity! = Null ){
// Obtain the active network connection
NetworkInfo info = connectivity. getActiveNetworkInfo ();
If (info! = Null & info. isConnected ()){
If (info. getState () = NetworkInfo. State. CONNECTED ){
Return true;
}
}
}
} Catch (Exception e ){
}
Return false;
}
There is a more detailed check method on the network, that is, list all connections. My personal feeling is generally meaningless. This is the simple version.
General Technology 2: Version Detection.
This is also a common feature, which is applicable to the applications currently seen.
Basic Flowchart
General Technology 3: data caching
Data caching is also a common technology.
Especially important for information applications.
Enter the display area to obtain the filled data:
Step 1: generate a unique file name based on network request parameters (MD5 is generally used, because the file named after this file name will be stored locally) for local retrieval.
If the file exists, execute Step 4. Otherwise, execute Step 2;
Step 2: normal network request operations;
Step 3: generate a unique file name based on the specified parameter to store the data locally;
Step 4: Data Acquisition and display;
The basic steps are as follows.
Extension of image resource cache.
In particular, the so-called image resources are a word we often mention during interviews: memory overflow.
Simple example: for example, the application Market in the Chinese Market.
The most resource in the app store is the image. A ListView drop-down will show the image. However, no matter how we pull the image, no error is reported during the application process. When we pull it down, we find that the image is asynchronously loaded and the default image is displayed first, the icon is displayed later.
This design involves two aspects: 1. image data cache, because every time we refresh the interface, it is impossible for us to request it again through the network. 2. Anti-memory overflow
The first point is very simple, as mentioned above.
The second point is actually not quite clear. The last time some friends said about the release to the C layer. I always thought that the reuse of the display view object can solve the problem, so that each image resource has a screen size.
Later I saw an article saying:
Try not to use setImageBitmap or setImageResource
Or BitmapFactory. decodeResource to set a large image,
Because after decode is completed, these functions are finally completed through the createBitmap on the java layer,
More memory needs to be consumed.
Therefore, use the BitmapFactory. decodeStream method first.
.........................
I don't understand the underlying layer. Whether it is useful or not, it is at least a precaution. For more information, see. The specific name of the article is forgotten, and Baidu will probably have it.
The above two points are actually not a problem because they are all solved.
However, for the sake of performance, I/O reading speed is understandable.
Then someone considers the image memory access. To prevent overflow, you can use soft references (the memory is automatically released before outMemory) or reference a queue (the memory temporarily stores recently used resources, and the overflow can be controlled by others ).
There is an open-source ImageManager class for a soft application (I don't know whether it is open source or not. I found this class in the previous project. The comments code is * Copyright (C) 2009 Google Inc ., I guess it is open-source. If you need it, you can search for the code ).
The improvement of memory temporary storage is to make the view refresh image load smoother and more perfect, but perfection also has a price.
With this design, data retrieval requires an additional memory retrieval step.
General Technology 4: network requests
Generally, companies encapsulate their own HttpClient classes or jar
Generally, there are three types of network requests on Android.
One is apache jar, and the other is HttpURLConnection in java. The third is forgotten.
I prefer apache because it divides every entity into classes. Use is refreshing. Of course, it is also a personal hobby.
General Technology 5: Network request protocol
Common XML and Json. Both are used. However, no native Api provided in Android is used.
Steps for a network request:
1. Generally, a javaBean and setter all the required parameters are used.
2. Convert bean to json or string in xml format.
3. Request and return.
4. Convert json or xml strings into beans
In fact, at the beginning, I naively assumed that the bean should be transferred after the transfer. Why directly transfer the bean file without serialization.
Later I learned that there is a sequence id for serialization, so the server and the client need the same serialization code. In this way, there is a problem with one-to-many servers and clients.
The second point is that the efficiency is very low.
For the parsing Api provided in Android, it seems that there is no direct bean2JsonObject implementation, that is, direct new JsonObject (beanobject )? It seems that no = is not noticed.
If you write the code yourself, you can use reflection to traverse the setter or getter method in the bean to concatenate the character seek.
XML is written by a buddy. For json, refer to a JSON.org package. I forgot where I downloaded it. Then, I slightly modified the getXXX reflection judgment,
Because the LZ makes the Bean into a Singleton, there is a getInstance () method in the Singleton, And it was depressing for a long time. After parsing it, stackxxxxx is the memory leakage. This is because no judgment is made on the newly mentioned get method and the Object Parsing is obtained infinitely.
Later I heard that the request protocol can also use the goggle protobuf protocol. It is said that the request is faster, several times faster, and FaceBook will put it here (I heard ).
However, it is not clear why the api is not provided directly by Google's own development sub-operating system.
Go to the document later. Thank you, boss.
General Technology 6: communication encryption www.2cto.com
This is too cumbersome. We must use a set of encryption for different companies.
I have used RSA asymmetric encryption. The simple process is to switch the Public Key between the client and the server while the application is enabling the network. Before the client data transmission
Use ClientPrivateKey to encrypt the data. After obtaining the data, the server exchanges the previous ClientPublicKey to decrypt the data. Likewise.
However, in my opinion, the attacker only needs to intercept the public key at the beginning .... ...
You are not involved in encryption. I don't know.
There is also the commonly used MD5 for tampering and 3des before MD5 encryption. However, security is not flattering.
Generally, if the application is decompiled, the keycode under the Encryption Class is obtained .. Then there is another tragedy ..
I think communication encryption is the most important part of the Internet in the future. Basically all applications are slowly designed to manage user names and passwords.
From mobile payment to smart home. I don't think anyone wants to be moved by someone else's wallet or house.
In the age of password explosion .. No one has dozens or even 20 passwords !!
General technology 7: Message push
This is definitely a disgusting but fascinating technology.
Such as previous malicious text messages.
Fortunately, the current applications basically have options for users to enable and customize.
Push information as needed.
Compared with Ios, Android provides such a unified framework. Although Android also has a uniform framework, it will not be uniform for a while.
Various pushes are introduced.
First: Resident backend services, regularly go to the server pull. To put it bluntly, this is really a pseudo push. The concept is completely illegal.
Type 2: persistent connections. In fact, I do not quite understand. Because our application is customized for China Telecom, China Telecom's demanding requirement is that there cannot be resident backend services and processes.
The rest are basically based on the second development framework.
Similar to the real-time chat application, which XMPP protocol is used .. All functions are available. This is used by instant messaging tools.
Here is google's C2DM framework. There are a lot of materials, but they are different.
There is also a well-known Androidpn framework. I plan to try this for a while, because the application cannot be used now.
I personally think this technology is quite good. I prefer custom reading, information, and group buying information as needed. Haha.
General Technology 8: Log
This is actually useless and may be used during development.
You can design your own log classes or packages at the security level as per your needs.
Organize yourself.
I'm tired of writing too much.
From Nono_Love_Lilith's column