How can a static inner class with a WeakReference outer class avoid Android memory leaks? Need an example

I studied this article, Avoid memory leaks . There are several suggestions to avoid memory leaks, one of which is below:

Avoid non-static inner classes in action if you are not in control of their life cycle, use a static inner class and make a weak reference to the activities inside. The solution to this problem is to use a static inner class with WeakReference for the outer class, as is done in ViewRoot and its inner class W, for example

1- Can anyone formulate this by providing an example?

2 How to use for static inner classes with weak references to inner classes?

3. What are the best practices for using this static class in your application to avoid memory leaks.

Many thanks.

+5
source share
1 answer

In this post, the answer shows a simple example of what you are looking for: How to create an interface in a fragment?

, , , , , (, ), , , () . : Android Fragment

, WeakReference, (, , ).

:

1) , getActivity(). onPostExecute() AsyncTask, .

2) null ( : , )

3) , isFinishing() - .

4) .

5) callback .

+1

All Articles