Skip to content

Instantly share code, notes, and snippets.

@vuhung3990
Last active March 10, 2016 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vuhung3990/915f2f09df3b560dee65 to your computer and use it in GitHub Desktop.
Save vuhung3990/915f2f09df3b560dee65 to your computer and use it in GitHub Desktop.
My Android Note
  1. tránh tạo các đối tượng không cần thiết

  2. sử dụng string buffer (multi thread) hoặc string builder cho việc append chiều chuỗi string

  3. hai mảng a[] b[] tốt hơn so với (a,b)

  4. Nếu bạn không cần truy xuất vào các biến của object. Có thể làm cho phương thức của bạn thành static. Lúc đó việc gọi hàm sẽ nhanh hơn khoảng 15-20%. Việc này cũng có một lợi thế nữa là method của bạn khi được gọi cũng không làm ảnh hưởng đến object

  5. Use Static Final For Constants, const int BIT BETTER than enum

  6. bên trong class thì bạn luôn luôn nên truy xuất trực tiếp vào biến (tránh gọi qua setter )

  7. foreach > fori

  8. cố gắng giảm thiểu độ sâu của layout

  9. (nên dùng leakcanary)

    • đóng các stream,lisnter, service để tránh leak
    • tối đa sử dụng Application Context, nếu cần thiết activity context sử dụng weak reference ( check null )
    • chú ý static inner class có thể keep strong reference đến outer class (RxJava instead of asynctask or loader )
  10. sử dụng support percent thay layout weight

  11. sử dụng okhttp (retrofit) hoặc voley thay cho apache httpclient mặc định

  12. luôn luôn sử dụng proguard cho các bản release build

  13. Sử dụng RxAndroid hoặc service, loader thay cho async

  14. Use Optimized Datacontainers

    SparseArray

    SparseBooleanArray

    SparseIntArray

    SparseLongArray

    LongSparseArray

  15. Try to avoid static variables or objects as much as possible if they are not final constants. Static variables pose the threat of having references in other classes, which we might forget about and thus cause a memory leak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment