Or to say "Happy New Year", the following is for you to share the daily development of Android 60 experience, for your reference, the specific content as follows
1. All activity can inherit from baseactivity, facilitate unified style and handle public events, build dialog box Unified Builder, in case of need for overall change, a change everywhere effective.
2. database table Segment field constants and SQL logic separation, clearer, recommend the use of the Lite Series Framework Liteorm Library, Super clear and focus can be placed on the business do not care about the details of the database.
3. Global variables put in the global class, the module private put in their own management class, so that constants clear and centralized.
4. Do not believe that the huge management of things will bring benefits, may be a disaster, but always pay attention to the principle of single responsibility, a class 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 position to deal with or centralized treatment, do not mess around with catch, chaos and low performance, try not to catch the exception in the loop body to improve performance.
7. Address reference chain long (more than 3 points) Beware of memory leaks, and alert stack address point, the typical easy event is: Data Update, ListView view is not refreshed, then adapter is likely to point to and is not your updated data container address (generally for list).
8. Information synchronization: Whether it is a database or network operation, the newly inserted data note returns the ID (if not given a unique ID), otherwise equivalent to no synchronization.
9. Multi-threaded operation of the database, DB shutdown will be an error, it is likely that the problem of interlock, the recommended use of transactions, the recommended 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 development, improve code reusability.
11. Orderly queue operation Add, delete operation attention to keep the sort, otherwise you will be more embarrassing oh.
12. Database delete data, pay attention to cascading operation to avoid the occurrence of never deleted dirty data oh.
13. About formal parameter arguments: When a function is invoked, the argument is a value, that is, a value, and a parameter is a reference to an object, that is, a pass.
ListView when the data is not full, the SetSelection function does not work, and when the ListView bulk operation, the subkeys and views correspond correctly, visible is the selected.
15 The amount of code that controls activity, keeping the main logic clear. Other classes adhere to the SRP (single function), ISP (interface Isolation) principles.
ArrayList notice the difference between int and integer when performing a remove. You know.
Log please tag, debugging and printing must be marked, can locate the print location, or embarrassment is: do not know where to print.
18. Block/constant/resources can be centralized common share, even if the logic of a little more complex will be worth it, modified easily, modified a, everywhere effective.
SetSelection does not work, try to smoothscrolltoposition. The Lastvisibleposition of the ListView (last visible subkey) changes as the GetView method executes at different locations.
20. It is more convenient to use handler with activity communication; If your frame callback chain becomes longer, consider the listener pattern to simplify the callback.
21. Listener mode is not convenient to use, recommended Eventbus frame library, the use of time bus, no contact with the students can make up their own brain oh.
Handler to make sure that the main thread is run when thread threads use Looper.prepare, or new, to pass Mainlooper to the constructor.
Timepicker Click OK after the Clearfocus to get the manual input time.
24. The constructor is extremely not recommended to start asynchronous threads, will be buried hidden dangers. For example, an asynchronous thread invokes the example of this example, and the tragedy waits for a crash.
25. Do not take for granted that an object will not be empty, adequate fault-tolerant processing; Note also that NULL can be inserted into containers such as ArrayList.
Expandablelistview's child list cannot be clicked (disabled) to return the adapter Ischildselectable method to True.
UI display notice that the content is too long to use in advance scrollview otherwise awkward on the small phone you know.
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 to enter user.
29. Server and client as far as possible unified unique identification (possibly is ID), otherwise how many will have ambiguity and the question.
30. Note, as far as possible to write enough comments, to describe the idea, to see can understand the effect of a piece of code.
31. The complete data must use the SQLite transaction, the big data must use. The rough test inserts 100 data to have 20 times times speed-up, inserts 1000 data to have 100 multiples acceleration.
32. Avoid string= "null" situations where a String = null,= "" Can be found. Avoid the waste of data submitted to the database title= "no Theme".
33. There are a number of different dbhelper instances, sqlitedatabase objects must exist in different instances, multithreading at the same time write data, the rotation of data will be written when the DB is locked, causing a crash, whether the operation of the same table or a different table. Read and write can be concurrent, alternating irregular alternate execution. When writing data at the same time, the solution is to use transactions with each concurrent thread, and DB will not lock and write as a whole.
34. It is recommended that the whole application maintain a dbhelper instance, as long as the DB is not closed, there is only one DB instance, multithreaded concurrent write DB will not lock, strictly alternating write: 123123123 ... (123 for different threads, take turns to insert a record), read and write will not lock db, reading and writing alternate and not regular, the number of executions and the extent to see the CPU allocated to which thread length of time.
35. A task to use transactions nested n transactions, there is a failure in n transactions, the overall failure of the task, all successful, the data is written, security, integrity. And the efficiency of transactions written to large quantities of data is more than a typical single write, with the actual Test hundreds of times. Database large amount of data, multithreading recommended the use of Liteorm database framework, more stable and simple.
36. Often need to use ListView or other controls display a large number of items in real-time tracking or viewing information, and hope that the latest entries can automatically scroll to the visual range. By setting the Control Transcriptmode property, you can automatically slide the control of the Android platform (support ScrollBar) to the bottom.
Long A; To determine if a is assigned a value, if (a = = 0) If a does not assign a value to the error. should be if (a = = null), Integer, FLOAG, etc. are the same, the reason you know, just remind you to be careful oh.
38. Code encountered reading and writing, access and other logic to consider two-way, file import and export, character byte to each other to convert both sides of the transcoding.
39. The size ratio of an int value to an Integer object (the smallest object that can contain int) is about 1:4 (32-bit and 64-bit machines differ). The extra overhead stems from the metadata that the JVM uses to describe Java objects, which is the Integer (Long, double, and so on).
40. Objects are made up of metadata and data. Metadata includes classes (pointers to classes, descriptions of class types), tags (describing object states, such as hash codes, shapes, and so on), 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 a 64-bit Java runtime.
The Hash collection's access performance is higher than any List's performance, but the cost per goal 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 are less focused on access performance. The performance of the ArrayList and LinkedList collections is roughly the same, but its memory footprint is quite different: ArrayList is much smaller than linkedlist per item size, but it is not exactly sized. The correct implementation of the list to use is ArrayList or LinkedList depending on the predictability of the list length. If the length is unknown, the correct choice may be linkedlist, because the collection contains less space. If the size is known or predictable or relatively small, the ArrayList memory overhead is lower.
43. Choosing the Right collection type allows you to strike a reasonable balance between collection performance and memory footprint. In addition, you can minimize memory footprint by adjusting the size of the collection correctly to maximize the fill rate and minimize unused space.
44. Make full use of encapsulation (provide interface classes to control access to data) and delegates (helper objects to implement tasks) two ideas.
45. Deferred allocation Hashtable: If Hashtable is a common occurrence, it should be reasonable to assign Hashtable only when there is data that needs to be stored. Assign Hashtable to the exact size: although there will be a default size, it is recommended that you use a more accurate initial size.
EditText don't forget to setselection when you settext. In most cases, it needs to be set.
Two things to note: 1 attribute names have duplicates, 2 note whether the text contains illegal characters, and use CDATA packages.
48. When the logic is not obvious problem, consider whether the object properties, function parameters, network transport parameters are fully understood, is set correctly.
49. When there is a compile or run-time error, when the other person has no problem, consider whether your compilation environment and environment version are problematic.
50. Because of the immutable nature of the string class, you should consider using StringBuilder to promote performance when a string variable needs to frequently transform its value, and multithreading uses StringBuffer to manipulate the string to improve program efficiency.
The advantage of the Java stack is that it is faster than the heap, can be shared, the main storage of temporary variables, parameters, etc., the advantage of the heap is the dynamic allocation of memory size.
52. As long as the new object is created with new (), it is built in the heap, and its data is stored separately, even if it is the same as the data in the stack, and is not shared with the data in the stack.
53. The basic data type defines the variable called the automatic variable, the deposit is ' literal value ', exists in the stack, can be shared (existence is not new).
54. Multiple Randomaccessfile objects pointing to the same file, can be written with multiple threads without locking themselves, the trial concluded that three threads write 1 million data, use a lock of about 12 seconds, and do not use about 8.5 seconds. 100 threads Write 10,000 data each time it takes about 4.2 seconds to use the lock, and it takes about 3 seconds to not use the lock.
Xmlpullparser parsing carefully using the Nexttext () method, XML is more complex, with empty tags, duplicate name tags prone to abnormal problems; use the GetText () method in text instead of the Nexttext () method in Start_tag Start_tag,text,end_tag three events are used together. Note The text event appears between each XML node, whether it is a start node or an end node.
56. Change the logic of the time to consider all the use of this function of the place, scattered more places, easy to effect.
57. When there is a problem with the native component 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 try catch to ensure that it does not crash. Do not disturb the normal logic of the system control.
58. Input control attention to the space, line, such as the control of symbols; Enter the contents of the box to notice and left and right control space to prevent late hit.
59. Note + + 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 wrong kill (try Catch), not let go.
The above is the detailed content of this article, I hope everyone in the new Year technology level of a higher, happy life!