答案 0 :(得分:6)
您可以在这种情况下使用WeakReferences。像这样的东西:
public class ContactsTask {
private WeakReference<Context> weakContext;
public void ContactsTask(Context context){
weakContext = new WeakReference<>(context);
}
public void doSomethings(){
if (weakContext!=null) weakContext.get() ... //return context without leaks
}
}