Summary of the knowledge points of the app development record

Source: Internet
Author: User
Tags image png switches

Original link: http://www.jianshu.com/p/fc8c4638937e

"App development Record" This book is written by Baojianchang, it is also clever, read the book before reading Chi Jianqiang "MAC life meta Programming", so read this book, the two build strong mix. The book took me a little more than a week to finish it. Last night to read a long sleepless, one is to marvel at the book's Dry goods too much, this book is different from other Android tutorials on the market, to tell you a bunch of API methods, Android Foundation, the author from an app team responsible for the perspective of strategically advantageous position app framework design, bug Collection Summary analysis, Team building, project management and so on, and are very well suited to the experience of the project manager of the app. The second is to admire the author to enter the field of Android is not a long time, but insightful, experienced, feel that they do Android also fast two years, why also reached no author's half height. Alas, it seems that the previous two years have been too easy, mixed daily, self-understanding of some Android technology, can realize the function of the product, on the muddle, no good use of time, seriously study, accelerate growth.

Digression too much, I think some things are superfluous, is their own moan, you crossing, you can ignore not look, directly see the following dry.

First, the APP framework 1. Project structure

Very much agree with the author's point of view, our app must have a good package structure, according to certain rules to put different classes in different places, there are two structures on the market, one is based on the type of class to be put together, such as activity class adapter, put together, etc. The other is to follow business logic, such as the home page logic in a small package, the user information logic in a small package, of course, the packet can be re-subcontracting.
Both can be, but must have a consistent project structure, do not make dubious, class everywhere, there is no certain rules

2. baseactivity, Baseadapter base class management 3. Network framework, encapsulating the network layer.
    • Do not use asytask because he is serial in the 4.x version, inefficient, and problematic when the number of request threads reaches the Asytask line. It is recommended to use the Theadpoolexecutor+runnable+handler method for encapsulation.
4. Data Caching Policy:
    • In order to reduce the number of requests for network data, it is necessary to cache data, the data of the request network, slow the presence of mobile phones, in order to ensure data immediacy, set the cache time, and can be based on the business requirements of different data set different cache time, some data can be set for a long time, some data changes frequently, The demand for immediacy is higher, the cache time setting is shorter, and the settings can be set without caching.
    • In addition, there must be an interface to enable users to force the update of data, such as users down to refresh, do not use the data in the cache, but directly request the latest network data
5. User Login
  • Consider user logins in various scenarios
    • A user starts logging in and then goes to the main page,
    • Two kinds of users do not have login data can not go to the next screen, need to jump to the login page, and then jump back,
    • Three user request network but user authentication failure requires jumping to the login registration page.
    • The first kind of say, the following two kinds of callback can be set to deal with, there is a situation may be more troublesome, such as the user entered a page without user information, need to jump back to the login registration page, but after registration is completed after the completion of the information to complete identity information, etc. finally, after a series of processes before jumping back to the original page
      1 //Start page, you may need to jump to sign in to the registration page2     if(User.islogin ()) {3          //Do something4}Else{5Intent intent=NewIntent ( This, Loginactivity.class){6Intent.putextra (Appconstant.needcallback,true);7 Startactivityforresult (intent,login_redieect_inside);8         }9     }Ten  One @Override A  Public voidOnactivityresult (intRequestcode,intresultcode,intent data) { -     if(resultcode!=ACTIVITY.RESULT_OK) { -         return; the       } - Swith (requestcode) { -         CaseLogin_redieect_inside: -            //Do something +              Break; -        default: +         Break; A     } at } -  - //Login Page loginactivity - if(Getintent.getbooleanextra (appconstant.needcallback) { - Setresult (ACTIVITY.RESULT_OK); - finish (); in }ese{ -    //Do otherthing to}
    • Risk of user information storage
      • The user's information is used in many places in the app, and we recommend that you persist it and store the file. Consider the failure of our users ' information.
      • In addition, the user's password must be encrypted processing, I recommend the client to the user input password encryption processing before passing to the server, the server to pass the password is also a layer of encryption, in order to ensure user security.
      • In addition, I do not recommend the storage of the user's password, immediately after the encrypted password, you can use the token mechanism (some also called a cookie mechanism), store tokens, this token can be used as a unique identity of the user identity. After the user client login, the server generates tokens, when the user calls the interface associated with the user information, the user ID and token to the server, the server first verify the user's correctness based on token and ID, and then pass the data to the user
    • Automatic login function
      • Automatic login function needs to store the user's password, need to pay attention to password security issues. and automatic login and transmission code repulsion problem.
    • Use cookie method to ensure user information security
      • When the user login is successful, from the background to get to Cookie,cookie in the Http-respose header file, we will take him out, the next time the network request data when the cookie is placed in the Http-request header file, if the request data related to user information, The server verifies the identity successfully before returning the data.
      • The client must update the cookie after each request.
      • Also note that the cookie expires, and the user log off, you need to clear the user information.
6. Prevent hackers from brushing the library
    • First method, add verification code at login
    • The second method, the login three times after the failure of the user to enter a verification code
    • The third method, background detection of a certain IP in a short period of time to access the login interface, and then the user entered a verification code.
7. Time Calibration Issues
    • This is an issue that needs to be considered if the background or the client has a higher requirement for time accuracy. Because the time on our user's mobile phone is not very accurate, generally have a certain deviation. The author recommends that the background take UTC time, including the entry and return values, and the return value is a long type. The client is converted to local time based on the resulting UTC time. This is a big problem if you need users to pass the time to the background accurately. Users there is actually difficult to get more accurate time, in addition to the user time zone problem, but also with accurate time deviation problem. Users can pass the time to the background, the background than the difference, and then each time the comparison to reduce the error, and finally find an accurate value.
8. Gzip compression
    • General HTTP uses gzip compression to reduce the amount of transmission and shorten the transmission time. However, in httprespose you need to determine if there is gzip in the Content-encoding field to determine if the background is gzip compressed.
9. Freso's Level three cache
    • First layer: Bitmap cache
      • In Android 5.0, consider memory management has made great progress, so bitmap cache in the Java heap, in the previous version of bitmap cache in Ashmen, when the app switches to the background, bitmap cache will be emptied
    • Second Layer: Memory cache
      • The inner cache stores the original compressed format of the image, taking the picture from the inner cache and decoding it before it is displayed. When the app switches to the background, the memory cache is also emptied
    • Tier Three: Disk cache, also called local cache
      • Local storage Image original compression format, display before also need to decode, when the app switch background, the disk cache will not be lost.
10. Flow optimization
    • Data compression (common gzip)
    • Use a better data delivery protocol. For example, better protobuffer than JSON
    • Merge APIs to prevent clients from calling API requests frequently
    • HTTP stateless short connection changed to TCP long connection. But need to have server and background requirements
    • Page destruction requires cancellation of previous network requests
    • Increase the retry mechanism, such as a GET request failed to retry three times, but need to prevent users to repeat the order, repeated comments, repeat payment, etc.
    • Picture request with dimension parameter, service side more size transfer picture of recent size.
    • Low-traffic mode, reduced image quality or size, and even the fastest mode of not returning pictures
11. Incremental Updates
    • Materials in the app, such as the city list, can use incremental updates. Each time the release material is guaranteed to be the latest version, when there is an update, first compare the local footage version number and the online footage version number, the background according to their version number to return the corresponding updates. After the client receives the decompression.
    • Incremental updates have three parts: data that needs to be deleted, unchanging data but needs to be modified, new data to be processed by the user according to the situation
Html Interchange Technology
    • When our app native page encounters a bug, you can switch to HTML page replacement right away.

Second, crash and continuous integration 1. Collection of Crash
    • Channels of collection
      • Integrates with third-party statistical tools. Friends Union, Leadcould
      • Integrated bug management tools, such as Bugly,bugtag
      • The app collects locally, logs the error log locally, and then sends it to the backend server, in addition to the crash time, crash name, details, phone version, device number, channel number, current network type, memory usage, and so on.
        Local bug collection needs to use UncaughtExceptionHandler this class
2.Crash Experience
  1. Form leakage problem, mainly want to close the popup box, he is carrying activity is not, and activity closed, not timely dismiss will lead to leak window handle, do not operate in sub-Threading dialog box, and let the dialog box is an activity member variable, Active between OnCreate () and OnDestroy () two methods, or dialogfragment is recommended.
  2. Only activity can add a form, and the context passed to dialog is activity.
  3. Do not trust API return data, must do non-null judgment, type exceptions such as fault-tolerant processing
  4. You cannot delete data in the collection while traversing the collection, or a crash occurs. A crash can occur when multiple threads concurrently manipulate the same set of data
  5. When a service or broadcastreceiver is in the context of a non-activity jump activity needs to be added Intent.FLAG_ACITIVITY_NEW_TASK .
  6. When the fragment is not attach to the activity call getResource().getString() will be an error, it is recommended to add judgment before the call isAdd()
  7. Parcelable when deserializing, for example, a=in.readParcelable(null) might throw a BadParcelabeException:ClassNotFoundException when unmarshalling... change to this line a=in.readParcelable(A.class.getClassLoader) .
  8. List<t> does not implement the Add (), remove () method, using both methods throws an exception, paying special attention to Arrays.aslis () returns LIST<T>, instead of ArrayList ();
  9. Whenever you modify the data of a collection in adapter, call the Notifydatasetchanged method immediately to ensure that the list is updated synchronously, or it crashes.
  10. ListView Scrolling Click refresh button will crash, because before GetCount also have data, scrolling when the data collection is cleared, GetView data is empty, report data out of bounds and other anomalies, the general solution is, scrolling, prohibit refresh.
  11. The Setfocusable () method cannot be called until Popupwindow is created.
  12. Popupwindow.showlocation (view parent,int gravity,in x,int y), when the parameter parent is empty, the report unable to add Windowtoken, This error is reported because Popupwindow to attach activity,activity has not oncreate () executed.
  13. The number of so packages in Armeabi and armeabi-v7a is inconsistent, resulting in unsatisfiedlinkerror.
  14. SQLite supports single-threaded, multi-threaded, serial three modes. However, using a single database connection in multi-threading is not secure, and when a thread writes data, an I/O exception is thrown when the data is deleted, and when one operation finishes shutting down the database, another operation also causes crash.
  15. <application android:largeHeap="true"You can increase the system to allocate memory for the current app, or even reach more than 100M, but each time the GC is extended, performance degrades.
  16. There are two kinds of caches in WebView: Web data caching, storing open pages and resources, HTML5 caching, and AppCache. WebView's own caching mechanism, will save the URL in the webviewcashe.db, the content of the URL is stored in the Webviewcashe folder, Web page data pictures, HTML, JS and other files will be stored.

Third, Proguard

The Proguard consists of the following 4 functions:

    • Compression (Shrink): Detectives remove useless classes, fields, methods, and attributes (Attribute) from the code.
    • Optimization (Optimize): Optimization of bytecode, removal of useless instructions
    • Obfuscation (obfuscate): Renaming classes, fields, and methods with an insignificant name such as a, B, C, D
    • Preflight (preverify): Pre-checks the processed code on the Java platform.

IV. Competitive Goods Analysis 1. Competitor app analysis Direction (for technology):
    • Why their app is smaller than ours
    • Why are they accessing the app faster than us?
    • Why their app is basically not crashing
    • Wait ...
2. Optimization measures
    • Splash Advertising Speed: The first time to load the picture in the app package, colleagues call the API to get the next open image URL, and store local, the next time Splash load downloaded new pictures, and call the API to see if there is a new Splash image to download.
    • HTML5 page Speed: The common HTMl5 into a zip package, each time you start, start an asynchronous thread, unzip the zip package to local, every time from the local read HTML5 page, you do not have to load the HTML page from the server. To ensure that HTML5 is up to date, each time you load the HTML5 page, you can ask the server HTML version number if it expires and re-download the latest Zip package.
    • The ZIP package uses an incremental update mechanism: The latest zip package is placed in the app installation package before each release. The client download Zip simply includes the new and modified on-line, in addition the control increment package within 100KB.
    • Png/jpg use: The mobile phone will be the PNG image hardware acceleration, the same image png size than JPG, but loading speed is much faster. The app image takes precedence in PNG format. But for large size images, JPG can be used to reduce the size of the APK package. Take into account the traffic and download speed need to download pictures of the network using JPG.
    • Use Webp,vetordrawable, TTF, etc.
    • Automatically select the best server policy: Multiple servers across the country, and access to telecom, mobile or unicom line, let the app try to connect from which server faster
    • TCP+PROTOBUF: The company has abandoned short connection Http+json, began to take Tcp+protobuf route. However, it is necessary to ensure the performance pressure of the server, considering the network situation.
    • Native pages and HTML pages are replaced with each other. When the native page crashes, use the HTML page top.

Summary of the knowledge points of the app development record

Related Article

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.