1 all Activity can be inherited from the BaseActivity, easy to unify the style and the processing of public events, the establishment of a unified construction of the dialog box, in case the need for overall changes, a modified everywhere.
2 database table segment field constants and SQL logic separation, more clearly, it is recommended to use 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 in the global class, the module of the private to put their own management class, so that the constant clear and concentrated.
4 do not believe that the huge management of what kind of things will bring benefits, may be a disaster, but to pay attention to the principle of a single responsibility, a class to do a thing more clearly.
5 if there is no need to load data, data, please be sure to delay the initialization, remember to save memory for the user, there will be no harm.
6 exception thrown, in the right location or centralized processing, do not engage in the catch, chaos and low performance, try not to catch abnormal in the cycle, to enhance the performance.
7. The address reference chain length (more than 3 points to) be careful memory leaks, and alert stack address points to, typical prone event is: to update the data, listview view without refresh when the adapter is likely to point and the not update your data container. (list).
8 information synchronization: whether it is a database or network operation, the new data is inserted into the ID (if not given only ID), otherwise equivalent to no synchronization.
9 multi-threaded database operation, DB will be closed down the wrong, it is likely to be the problem of interlocking, recommended the use of transactions, recommended the use of automated LiteOrm library operations.
10 do before you consider the public, resource, layout, class, do a structure, architecture analysis to speed up the development, enhance the code reusability.
11 orderly queue operation add, delete operation, pay attention to maintain order, otherwise you will be more embarrassing oh.
12 database to delete the data, the need to pay attention to the cascade operation to avoid the dirty data can not be deleted forever oh.
13. A parameter argument: when we call the function parameters for basic types of value, value; transfer parameters for object references that address.
14. The listview when data is not full Yiping, function setSelection not role; listview batch operation sub item and view the correct correspondence, visible is the selection.
15 control the amount of Activity code, to maintain the main logic clear. Other classes to comply with the SRP (single function), ISP (interface isolation) principle.
16 ArrayList remove to remove the int and Integer when the difference between the removal of. You know.
17 Log please call Tag, debug print must make the mark, can locate the print position, otherwise the embarrassment is: do not know where to print.
18 code block / constant / resource can be shared with the public, even if the common logic is slightly more complex will be worth it, modify it very easily, modify one kind, everywhere.
19 setSelection does not work, try smoothScrollToPosition. LastVisiblePosition's ListView (the last visible Zi Xiang) will change as the getView method performs different changes.
20 communication with Handler is more convenient to use Activity; if your frame callback chain becomes longer, consider listener mode to simplify callback.
21 listener mode is not convenient to use, recommended EventBus framework library, the use of time bus, no contact with the students can make their own brain to fill it up.
22 Handler in the thread of the thread using Looper.prepare, or new when the MainLooper to the constructor to ensure that in the main thread run.
23 TimePicker Click To determine the need for clearFocus to get the manual input of the time.
24 constructor which is extremely not recommended to start the asynchronous thread, will lay hidden. For example: the asynchronous thread calls the example of this example, it will be a tragedy and so on the collapse of it.
Don't take it for granted that an object will not be empty, full of good fault tolerance processing; also note that null can also be inserted into the ArrayList and other containers.
26 ExpandableListView sub list can not be clicked (disabled) to the isChildSelectable Adapter method to return true.
27 UI shows that the situation should pay attention to the situation in advance to use the ScrollView or in a small cell phone embarrassed you know.
28 note that the range of the sensor is not less than 9mm, otherwise it is not easy to click; the input box to pay attention to the position of the cursor is more user input.
29 server and client as far as possible to unify the unique identity (there may be ID), otherwise how many will have ambiguity and problems.
30 notes, as far as possible to write enough notes, to describe the ideas, to see the effect of a piece of code can understand.
31 complete data must be used Transaction Sqlite, big data must be used. The test data are inserted into 100 roughly 20 times the speed, speed into 1000 data is 100 times.
33. There under a number of different dbhelper instances, sqlitedatabase must exist different instances, multiple threads at the same time to write data, take turns to write data will be regularly reported to the DB is locked, cause a crash, whether it is operating with table or different tables. Read and write can be concurrent, alternate execution of rotation. At the same time the data is written to the solution is to use the concurrent threads of each transaction, DB is not lock, according to the overall write.
34 suggested that the entire application to maintain a dbhelper instance, as long as the DB is not closed, the overall situation is only one DB instance, multi-threaded concurrent write DB will not be lock, strictly alternating write: 123123123... (123 represents different thread turns into a record), reading and writing are not locked dB, read and write alternating does not have the rule, and the number of the implementation of the allocation of CPU to which thread time slices.
35 a task to use nested transactions N transactions, N transactions have a failure, the overall failure of this task, all successful, the data is written, with security, integrity. And the efficiency of the transaction to the large quantities of data through the actual test hundreds of times higher than the general single write. Database of a large number of data, the use of multi thread operation LiteOrm database framework, more stable and simple.
36 often need to use ListView or other display a large number of Items control real-time tracking or view information, and hope that the latest entries can be automatically scroll to the visual range. By setting the transcriptMode property of the control, you can automatically slide the control (support ScrollBar) of the Android platform to the bottom.
37 Long a; judge a has no assignment, if (a = = 0) in a no assignment case will error. Should if (a = = null), Integer, Floag and other reasons too, you know, just want to remind you to be careful.
38 encoding encounter read and write, access and other logic to two-way consideration, the file import and export, character byte conversion is to both sides of the transcoding.
39 A int value with a Integer object (the smallest object that can contain the int value) is about 1:4 (32 bit and 64 bit machines). The additional overhead comes from the JVM that is used to describe the metadata for the Java object, which is also called Integer (Long, Double, etc.).
40 objects are composed of metadata and data. The metadata includes a class (pointer to the class, the type of the class), the tag (describing the object state, such as the hash code, shape, etc.), and the lock (object synchronization information). Array objects also include the size of the metadata.
41 a Java application that uses the Java 1GB heap in the 32 bit Java runtime to migrate to the 64 bit Java runtime, usually requires the use of Java 1.7GB heap.
The access performance of the 42 Hash set is higher than the performance of any List, but the cost of each target is higher. As a result of the access performance, if you are creating a large collection (for example, for Implementation), it is best to use a collection based on Hash without having to consider additional overhead.
43 for small collections that are not so focused on access performance, List is a reasonable choice. The performance of the ArrayList and LinkedList collections is roughly the same, but its memory footprint is completely different: the ArrayList of each item is much smaller than the LinkedList, but it is not exactly set size. The correct implementation of 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 space. If the size of the known or predictable or relatively small, then the memory cost of ArrayList will be lower.
43 choose the right set of types so that you can achieve a reasonable balance between performance and memory usage. In addition, you can maximize the fill rate by properly adjusting the set size, minimize the amount of space that has not been used, thereby minimizing the memory footprint.
Two full use of the package (to provide interface class to control access to data) and the Commission (helper objects to implement the task) 44 concepts.
45 delay allocation Hashtable: if the Hashtable is empty is a common phenomenon, it should be a reasonable way to allocate Hashtable only when there is a need to store the data. Hashtable will be allocated to the correct size: Although there will be the default size, but it is recommended to use a more accurate initial size.
46 setText in the EditText do not forget if you need to setSelection. In most cases it needs to be set up.
47 XML two cases should pay attention to: 1 attribute names when there are repeated; 2 pay attention to whether the text contains illegal characters, pay attention to the use of CDATA package.
48 when there is no obvious problem of the logic to consider the object properties, function parameters, network transmission parameters are all known, whether set the correct.
49 when there is a compile or run time error, others that no problem, consider your compiler environment and the environment version is a problem.
50. Due to the nature of an immutable string class, when string variables need to be constantly changing the value should consider use StringBuilder to enhance performance, multi-threaded use StringBuffer string operation to improve the program efficiency.
51 Java stack advantage is faster than the heap, can be shared, mainly to store temporary variables, parameters, etc., the heap is the advantage of dynamic allocation of memory size.
52 as long as the use of new () to new objects will be created in the heap, and the data is stored separately, even with the stack data (values), and will not be shared with the data in the stack.
54. Multiple RandomAccessFile object points to a file, write together without the need to add their own lock using multiple threads, the conclusion of the experiment: three threads were written data of 100 million times, using a lock of about 12 seconds, without the use of about 8.5 seconds. 100 threads are written to the 10 thousand data using the lock takes about 4.2 seconds, not to use the lock takes about 3 seconds.
55. Xmlpullparser analytical caution nextText () method for, XML is more complex, with a null label, to repeat the name of the label is prone to abnormal problem; text using gettext () method instead of the start tag using nextText () method, the start tag, text, and end tag three events with use. Note that the TEXT event occurs between each XML node (whether it is the start node or the end node).
56 to change the logic of the time to consider all the use of this feature, the spread of more, easy to the effect.
57. When the primary components of the system when there is a problem, check error stack information, himself wrote a the component sub classes and in the right place will replication error method, and try to catch promise not to fall apart. Do not disturb the normal logic of the system control.
58. The input control attention of spaces, newlines symbols control; input box in attention and control about the space to prevent mistaken click.
60 all kinds of places, never underestimate the null pointer, and even some occasions rather wrong to kill (catch try), can not let go.