I know this has been asked many times but still many new developers like me finds it difficult.To avoid memory leaks
which context
should be used?.
Somewhere i found that we should getApplicationContext()
and somewhere that try to use context-activity
as possible.Also http://android-developers.blogspot.in/2009/01/avoiding-memory-leaks.html says
Try using the context-application instead of a context-activity
For eg
Which Context to pass to RecyclerView Adapter
or to a Custom Dialog Class
One way i found is to pass context to adapter in this way
recyclerview.setAdapter(new YourAdapter(new WeakReference<Activity>(ActivityName).get()));
Is my way of passing context is right?
Please do a give detailed explanation so that others also gets benefitted. Thanks