A technical Daniel's post (Android project summary)

Source: Internet
Author: User

1. General controls need to set the OnClick event to have a click effect (selector).

2. <item android:drawable= "@drawable/btn_ct_green"/> To be written at the end of selector will have a click effect.

3. Create. 9 format Picture Select the minimum, otherwise the default size brace large control. 4. If the property of an object is set to static, then even if the object instance is recycled, the property also has memory, and the lifecycle is the app's life cycle. 5. OOM: Picture control for large data volume display views such as normal view and listvew are separated. 6. The list of Oom:listview and so on 1 seconds really released, the large data load after the use of the image released. 7. OOM: Large picture compressed before use. 8. OOM: Reduce the big picture. The artwork minimizes all rule diagrams and makes. 9 format to minimize memory consumption. 9. OOM: Background map, large map careful use, irregular large-picture explicit release. 10. Know in advance the size can be used, view.measure (-1,-1); But the view must have a parent view. One. The ListView list renders multiple styles, the Getviewtypecount () method returns the total number of styles, and the value returned by Getitemviewtype (int pos) must be less than getviewtypecount () or an error.

12. Public class, interface, base class design to be clear and easy to understand the responsibility, the most significant reduction in the use of others difficult.

Oom:webview memory Overflow (OOM), restart a new process. and set: Need to stop the timer at OnPause, solve the problem due to the timer in, cause webcorethread has been, webviewcache.db is locked, graphics details can not enter the question Webview.pausetimers (); When activity returns to Onresume webview.enableplatformnotifications (); WebView. Resumetimers (); 14. Touch range to be used as a specification to control the development of each step, there is the SRC attribute can be set padding, not for distortion, set a layout, the minimum width of 48DP (9mm). 15. Request with timestamp Please note that the YY-MM-DD Hh:mm:ss is in the 12-hour format. Yy-mm-dd HH:mm:ss is a 24-hour format. The difference is huge. 16. The package type of the underlying data type is pre-loaded, the JVM caches the -128~127 object for Byte, and the integer caches the -128~127. So the Integer i =k,integer j =k,,k = 127,i = = J is true,k=128 false. 17. The logic conditions to be cautious, relax more carefully, relax after considering whether to cause side-effects problems, poly-cost will id= (), itemid= (), I () all grabbed the details, the result of frequent innocent pull up. After tightening consider whether it will cause expansion problem 18. Last minuteAdd the code to rigorous testing, many times it is the last ' thought ' added ' irrelevant ' things that lead to collapse. Math.Abs () is not necessarily a positive number, Integer.minvalue is a negative value. 20. Multithreading use concurrent containers to place variables, it is not easy to think that there is less chance of conflict, the concurrency of a large number of possible. Threadpool.shutdownnow () Only clears the wait queue, and then waits for the active thread to finish executing. 21. Make sure the object is not empty before the strong-to type. android2.3 the following version of the Listview.setdividerheight () function is called, notifydatasetchanged () cannot remember the location. You can use SetSelection to remember locations. Finish and startactivity locations are important. From A jump to Singletask's activity b,a.finish position before startactivityb, Exit B Press Home to return (home key exit or back key FINISHB) The application interface is still B, Whether or not B is action.main,overridependingtransition need to be available after finish or startactivity. 24. Zone Event interception: For example, if Viewa gets a click event and organizes its parent control and other child control trigger events, it can override the activity's dispatchtouchevent () function, call Viewa.gethitrect (rect), Initializes a rect, judging the event's getx and gety if within REC, the Intercept Action_down returns True, and the remaining action calls Viewa. dispatchtouchevent () to intercept the events. 25. One effective touch, when Action_down returns ture, other events will not be responding. When an event is outside of a rect, it can be event.setaction (motionevent.action_down), Activity.ontouchevent, to re-trigger events. WebView: Caching and non-caching are critical. Especially in the activity, timing, including the session interface. WebView: When WebView consumes a lot of memory, you can start all WebView in another process. WebView: When multiple redirects interfere or cannot go back to the previous page, do not use Webview.goback (),Stack maintenance URL, the key is to distinguish whether it is redirected, the current use of Java call JS to obtain, analyze the content of the Web page to determine whether to redirect, if not the URL into the stack, but not into the stack. 29.  Radio Wave State machine: The application runs in the foreground to consider avoiding delay blocking, running in the background concerned about the waste of power. Optimize network connectivity: prefetch data, bulk transfer and connection (including carry, incidentally other data), reduce the number of connections (avoid high-frequency heartbeat). 30. When the ListView contains a header, in the Onitemclick event, obtain itemobject:object obj = Parent.getadapter (). GetItem (position); The first sentence is empty, then strong to the desired object. WebView: Note the support for the download file, Shouldoverrideurlloading returns false, the page is automatically loaded, and true does not load the Web page and requires its own processing (before returning true, calling Webview.load (URL) The result is that the redirect page can not be rolled back, it took a lot of cost to solve, directly return false will automatically load). 32. Use a function, especially a function written by someone else, no matter how sincere the commitment parameter is not NULL, please try to do non-null judgment. Before dividing by a variable, make sure it is not 0.33. If the program is self-automatic, or the background consumes traffic, first detect the static registered broadcast in manifest, it will pull up the program. FindBugs combined with the problem in the lint detection program that comes with ADT (16), lint can detect unused images and more Android-specific issues. After View onmeasure, width does not necessarily have a value, if Layoutparagrams is set then View.getlayoutparams (). Width will have a set value. Gallery features improved: One touch only switches one picture: The replication onflying directly returns true; Makes the touch more sensitive: replication Onscroll calls Super.onscroll (E1, E2, Distancex * 1.5f, Distancey), making the distancex  bigger is more sensitive. Gallery Visual Optimization: Setstatictransformationsenabled (True) after the Getchildstatictransformation method takes effect, the default method causes the image alpha value to change and is visually unclear , replication can use the camera to produce xyz and angle changes,This optimizes the visual experience, such as creating a 3D gallery. 38. Common object Properties use static to keep a copy of the saved resources, and the properties that each instance or object enjoys separately should not be static. 39. Change the private property of a class: Field field = ViewGroup.class.getDeclaredField ("HSL"); Field.setaccessible (true);  field.set ( ListView, 0); 40.  which client is the best?

Apache HTTP Client has fewer bugs on Eclair and Froyo. It's the best choice for these releases.

For gingerbread and better, httpurlconnection are the best choice. Its simple API and small size makes it great fit for Android. Transparent compression and response caching reduce network use, improve speed and save battery. New applications should use httpurlconnection; It is where we'll be spending going forward.

Http://www.vmatianyu.cn/poly-effective-client-1-issues-lessons.html

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.