apk development framework! Detailed Android custom View, Android post

Preface

The great man once said:

Books are the ladder of human progress.
Books have their own house of gold, and books have their own Yan Ruyu.
Books have broken through ten thousand
books , and if there are gods in writing, books are the only things that never die.
Books are the legacy of a great genius to mankind.

Recently, many friends have asked similar questions on my official account, such as "Classic introductory textbooks and learning routes for Android development?", "What are the recommendations for Android development introductory tutorials?" and other similar questions. We keep answering these questions repeatedly, which made me inspire To do the  2020ndroid development hot book recommendation: from Xiaobai-Android Senior Engineer series of learning route book introduction ideas , organize and collect the learning experience of the development of big cows, so that we can avoid detours and grow faster. Hope this article can be a good answer for everyone to deal with novices.

Here I provide you with a diagram of the advanced knowledge system of Android senior architects, and get it yourself!

Next, I will follow this route to introduce to you. I and some friends around me have read books that are good.

What is a memory leak?

A memory leak that is ML (Memory Leak)a phenomenon in the application program memory, when the memory do not need to use but can not be returned to the program released &

What are the memory leaks and the corresponding solutions?

In the final analysis, the cause of the memory leak is that when the memory of the variable that needs to be recovered is held by other variables, the memory recovery fails.

Common reasons are:

1. Non-static inner class/anonymous class

  • Reason 1: 非静态内部类/匿名类 HandlerHolding Activity/Fragmenta reference to an external object, Activity/Fragemntit was not recycled when it was destroyed

  • solution:

    1. Change the Handler class to static internal class + weak reference ( WeakReference) to hold Activityreferences (static classes do not hold external references by default)
    2. When the external class (usually Activity/Fragment) ends its life cycle, clear the Handler queue
  • Reason 2: 非静态内部类的实例(对象)= 静态实例(its life cycle = application life cycle)

  • solution:

    1. Change the class to static class (static class does not hold external references by default)
    2. Extract the class and encapsulate it as a singleton
  • Reason 3: The external class needs to be destroyed when the multi-threaded worker thread is processing a task. At this time, the worker thread holds a reference to the external class and cannot be recycled

  • solution:

    1. Change the thread class class to static class (static class does not hold external references by default)
    2. Force the end of the thread when the external class ends its life cycle

2. Collection

  • Reason: The collection class holds a reference to the collection element after adding an element, which causes the collection element to be uncollectible, resulting in a memory leak

  • solution:

    1. After the collection class uses the element object, the element must be deleted from the collection (because there are multiple elements in a collection, the simplest solution is to empty the collection object (clean) & set to Null)

3. The resource object is not closed after use

  • Cause: The resource object is not closed after use, there is no off / log off when these resources are destroyed Activity / Fragemnt, will not lead to recovery such as: 广播BraodcastReceiver, 文件流Fire, 图片资源Bitmap, 数据库游标etc.

  • solution:

    1. ActivityTimely close/deregister resources when destroyed

4.Static keyword modifies member variables

  • The reason: Static keyword modified member variable life cycle = life cycle applications such as private static Context mContext = contextso context corresponding to the context Activitycan not be recovered

  • solution:

    1. Try not to use Static member variable references, use weak references instead of strong references
    2. Use singleton pattern

4. Other uses

  • Reason 1: Context: When Activity contextthe referenced object is still in use, it Activitycannot be recycled when it needs to be destroyed

  • solution:

    1. The right contextreference should not exceed its life cycle
    2. Use ApplicationContextinstead
  • Reason 2: WebView: The WebView object is not destroyed in time after it is no longer used, resulting in memory usage

  • solution:

    1. WebViewDestroy objects that are no longer used through multiple threads
  • Reason 3: Adapter: When sliding ListView and RecycleView to obtain a new View, a View object is re-instantiated in getView(), which wastes resources and makes the memory usage larger and larger

  • solution:

    1. Use cachedconvertView
    2. Use directlyViewHolder

In addition to flutter, what else must be mastered in Android development?

I believe that most of the friends who are engaged in Android development are finding that finding a job is getting harder and harder and the requirements for interviews are getting higher and higher.

In addition to a solid basic knowledge of java, data structure algorithms, and design patterns, the underlying source code, NDK technology, performance tuning, and some small programs and cross-platforms, such as flutter, are shown in the figure below as a mind map;

Click on the document to get interview materials and video tutorials; [Ali P7 level Android architect technical mind map + full set of videos]

9D%A2%E8%AF%95%E6%8B%BF%E9%AB%98%E8%96%AA%EF%BC%81.md)**

[External link image is being transferred...(img-xYPrZ6zZ-1611397302162)]

Guess you like

Origin blog.csdn.net/weixin_52746928/article/details/113059782