Android Development 60 Technical Experience Summary (turn)

Source: Internet
Author: User
Tags unique id

Android Development 60 Technical Experience Summary:
  • 1. All activity can inherit from Baseactivity, it is easy to unify style and deal with public events, build a dialog Unified builder, in case the overall change is needed, a modification is available everywhere.
  • 2. database table Segment field constants and SQL logic separation, clearer, the recommended Use Lite Series Framework Liteorm Library, Super clear and focus on the business can not care about database details.
  • 3. Global variables in the global class, the module is privately placed in its own management class, making the constants clear and centralized.
  • 4. Do not believe that the huge management of things will bring any benefit, it may be a disaster, but always pay attention to the principle of single responsibility, a class to concentrate on doing a thing clearer.
  • 5. If the data is not necessary to load, the data must be delayed initialization, remember to save memory for users, there is no harm.
  • 6. Exception thrown, in the appropriate location or centralized processing, do not engage in catch, chaos and low performance, try not to catch exceptions in the loop body to improve performance.
  • 7. When the address reference chain is long (more than 3 points) Beware of memory leaks, and be wary of stack address pointing, the typical easy-to-send event is: The data is updated, the ListView view is not refreshed, then adapter is likely to point to and not your updated data container address (typically list).
  • 8. Information synchronization: Whether it is a database or a network operation, the newly inserted data is aware of the return ID (if no unique ID is given), otherwise it is equivalent to no synchronization.
  • 9. Multi-threaded operation of the database, DB shutdown will be an error, it is also likely to have interlocking issues, recommend the use of transactions, recommended the use of automated Liteorm Library operations.
  • 10. Before doing, consider those that can be public, resource, layout, class, do a structure, architecture analysis to speed up the development, and improve the reusability of code.
  • 11. Orderly queue Operations Add, delete operations pay attention to maintain the sort, otherwise you will be more embarrassed oh.
  • 12. When deleting data from the database, be aware that cascading operations avoid dirty data that will never be erased.
  • 13. About formal parameter arguments: When the function is called, the argument is the value of the basic type, that is, the value is passed, and the argument passes the reference to the object, that is, the address.
  • In the ListView, the SetSelection function does not work when the data is not full, and the ListView and the view correspond correctly for the batch operation, and are visible as selected.
  • 15 control the amount of activity code, keeping the main logic clear. Other classes adhere to the SRP (single function), ISP (interface Isolation) principle.
  • ArrayList remove the difference between int and integer when you execute remove. You know.
  • . log please tag, debug printing must be marked, can locate the print position, or embarrassment is: do not know where to print.
  • 18. Code blocks/constants/resources can be centrally shared, even if the common logic is a little more complex, it will be worthwhile to modify it easily, modify one, and be effective everywhere.
  • SetSelection does not work, try to smoothscrolltoposition. The Lastvisibleposition of the ListView (the last visible subkey) changes as the GetView method executes at a different position.
  • 20. It is more convenient to use handler with activity communication, if your frame callback chain is longer, consider listener mode to simplify callbacks.
  • 21. When the listener mode is not convenient to use, it is recommended that Eventbus frame library, using time bus, the classmate who has not contacted can mend the brain by himself.
  • Handler a child thread thread uses Looper.prepare, or new to pass the constructor to the mainlooper to ensure that it is run on the main thread.
  • Timepicker Click OK and need Clearfocus to get the time manually entered.
  • 24. In the constructor, it is highly deprecated to start the asynchronous thread, which will bury the hidden danger. For example, if an asynchronous thread invokes the example of this example, the tragedy waits for a crash.
  • 25. Do not take for granted that an object will not be empty, sufficient to do fault-tolerant processing; Also note that null can be inserted into containers such as ArrayList.
  • The sub-list of Expandablelistview cannot be clicked (disabled) to return the adapter Ischildselectable method to True.
  • UI display Note that the situation is too long to use in advance scrollview otherwise on the small phone embarrassed you understand.
  • 28. Note that the sensor range of the button is not less than 9mm or not easy to click; Input box note the position of the cursor is easier for user input.
  • 29. The server and the client as far as possible uniform unique identification (may be ID), otherwise there will be ambiguity and problems.
  • 30. Note, as far as possible to write enough comments, to describe the idea, to see that you can understand the effect of a piece of code.
  • 31. Complete data must use SQLite transaction, big Data must be used. A rough test inserts 100 data 20 times times faster, and inserting 1000 data will speed up the 100-fold acceleration.
  • 32. Avoid string= "null" in cases where string = null,= "" is possible. Avoid the title= of "no themes" such as data submission to the database wasted space.
  • 33. There are a number of different dbhelper instances, the Sqlitedatabase object must exist different instances, multi-threaded simultaneous writing data, the data will be written in turn to the DB is locked, causing the crash, whether it is the operation of the same table or a different table. Reading and writing can be concurrent, alternating and irregular alternately executed. When writing data at the same time, the solution is to use a transaction for each thread that is concurrent, and the DB does not lock and write as a whole.
  • 34. It is recommended to maintain an DBHelper instance for the entire application, as long as the DB is not shut down, there is only one DB instance globally, multi-threaded concurrent write DB will not lock, strictly alternating write: 123123123 ... (123 on behalf of different threads, in turn insert a record), read and write will not lock the DB, read and write alternating with no regularity, the number of executions and the degree of the CPU allocated to which thread of the time slice length.
  • 35. A task uses transactions to nest n transactions, there is a failure in n transactions, the overall failure of the task, all successful, the data is written, with security, integrity. And the efficiency of a transaction to write large quantities of data is actually tested hundreds of times higher than the average single write. It is more stable and simple to use Liteorm database framework for large database data and multi-threaded operation.
  • 36. It is often necessary to track or view information in real time with a ListView or other control that displays a large number of items, and you want the latest entries to automatically scroll to the viewable range. By setting the Control Transcriptmode property, you can automatically slide the controls on the Android platform (support ScrollBar) to the bottom.
  • PNs. Long A; Determine if a has an assignment, if (a = = 0) An error will be given in the case of a without assigning a value. Should if (a = = null), Integer, Floag, and so on, the reason you understand, just remind you to be careful oh.
  • 38. The code encountered reading and writing, access and other logic to two-way consideration, file import and export, character byte conversion between each side to transcode.
  • 39. The size ratio of an int value to an Integer object (the smallest object that can contain an int value) is approximately 1:4 (32-bit and 64-bit machines are different). The additional overhead is derived from the metadata that the JVM uses to describe the Java object, which is the Integer, (Long, double, etc.).
  • 40. The object consists of metadata and data. Metadata includes classes (pointers to classes that describe the type of Class), tags (which describe the state of an object, such as hash codes, shapes, and so on), and locks (object synchronization information). The array object also includes the size of the metadata.
  • 41. A Java application that uses the 1GB Java heap in a 32-bit Java runtime is typically required to use a 1.7GB Java heap after migrating to the 64-bit Java runtime.
  • The access performance of the Hash collection is higher than any List performance, but the cost per purpose is higher. For access performance reasons, if you are creating a large collection (for example, to implement caching), it is best to use a Hash-based collection, regardless of the additional overhead.
  • 43. List is a reasonable choice for smaller collections that do not pay much attention to access performance. The performance of the ArrayList and LinkedList collections is roughly the same, but their memory footprint is completely different: ArrayList has a much smaller size per entry than LinkedList, but it is not exactly set to size. The correct implementation of the list to be used is ArrayList or linkedlist depending on the predictability of the list length. If the length is unknown, then the correct choice may be linkedlist, because the collection contains less white space. If the size is known or predictable or small, the memory overhead of ArrayList is lower.
  • 43. Choosing the Right collection type allows you to strike a reasonable balance between collection performance and memory consumption. In addition, you can minimize the memory footprint by properly resizing the collection to maximize the fill rate and minimize unused space.
  • 44. Take advantage of the two concepts of encapsulation (providing interface classes to control access to data) and delegates (helper objects to implement tasks).
  • 45. Deferred allocation Hashtable: If Hashtable is a common phenomenon that occurs frequently, it should be reasonable to allocate Hashtable only if there is data that needs to be stored. Assign Hashtable to the exact size: although there will be a default size, it is recommended to use a more accurate initial size.
  • EditText in SetText don't forget whether you need setselection. In most cases it is necessary to set the.
  • Two things to note in XML: 1 attribute names are duplicated, 2 note whether the text contains illegal characters, note the use of CDATA parcels.
  • 48. When the logic does not have obvious problems, consider the object properties, function parameters, network transport parameters are all understood, whether set correctly.
  • 49. When there is a compile or run-time error, other people that no problem, consider your compilation environment and environment version if there is a problem.
  • 50. Because of the immutable nature of the string class, when a string variable needs to change its value frequently, consideration should be given to using StringBuilder to promote performance, and multithreading uses the StringBuffer action string to improve program efficiency.
  • The advantages of the Java stack are faster than the heap, shareable, mainly temporary variables, parameters, etc., the advantage of the heap is to dynamically allocate memory size.
  • 52. As long as new () is used to create the object, it is created in the heap and its data is stored separately, even if it is the same as the data (value) in the stack, it is not shared with the data in the stack.
  • 53. The variables defined by the basic data type are called automatic variables, which are stored as ' literal values ', which exist in the stack and can be shared (i.e., not created).
  • 54. Multiple Randomaccessfile objects point to the same file, can be written with multiple threads without having to lock themselves, the experimental conclusion: three threads write 1 million data respectively, use the lock for about 12 seconds, do not use about 8.5 seconds. 100 threads write 10,000 data using a lock takes about 4.2 seconds, and it takes about 3 seconds to not use a lock.
  • Xmlpullparser Analysis of the Nexttext () method, XML is more complex, with empty tags, duplicate name tags prone to abnormal problems; text using the GetText () method instead of Start_tag using the Nexttext () method ; Start_tag,text,end_tag three events in conjunction with each other. Note The text event occurs between each XML node, either the start node or the end node.
  • 56. Change the logic of the time to consider all the use of this function, scattered places more, easy to careless.
  • 57. When there is a problem with the native components of the system, look at the error stack information, write a subclass of the component yourself, and make a copy of the error method where appropriate, plus the try catch guarantee does not crash. Do not disturb the normal logic of the system control.
  • 58. Input control note the control of the symbols such as spaces, line breaks, and the contents of the input box and the left and right control space to prevent accidental hits.
  • 59. Note the + + or – operation in function parameters. is ++c or C + +, the difference is very big.
  • 60. A variety of places, never underestimate the problem of NULL pointers, and even some occasions rather than the wrong to kill (try Catch), do not let go.

Android Development 60 Technical Experience Summary (turn)

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.