Last active
July 6, 2016 18:57
-
-
Save alexvbush/7177814 to your computer and use it in GitHub Desktop.
An example of how to store an Android Context object in a weak reference to avoid unexpected retain loops in adapters and such.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExampleWeak { | |
private WeakReference<Context> weakContext; | |
public ExammpleWeak(Context context) { | |
this.weakContext = context; | |
} | |
public Context getContext() { | |
return weakContext.get(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment