What is the corrent way to unbind views in onDestroyView()
Closed this issue ยท 8 comments
Hi,
Previously I was using unbind()
method but now in v8 of ButterKnife, there's no such method and just the binding method returns an Unbinder
which will help with that. But the question, what is the correct way to do that? Is it recommended in fragments?
Create a field in your fragment as
Unbinder unbinder;
in onCreateView you call
unbinder = Butterknife.bind(this, root);
and in onDestroyView you need to call
unbinder.unbind();
thats it you're done.
Yes it is, It will set your bindings to null, freeing up memory...take a look at
BINDING RESET at
http://jakewharton.github.io/butterknife/
Sorry to ask this, but why the change from the simple Butterknife.unbind()
?
Warm regards,
A user who just upgraded from previous version
So listeners can be cleared
On Thu, Sep 1, 2016 at 11:47 PM Aiman B notifications@github.com wrote:
Sorry to ask this, but why the change from the simple Butterknife.unbind()
?Warm regards,
A user who just upgraded from previous versionโ
You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub
#585 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEVF99TB6Xo-aw14UVCnx8AAcGWtZks5ql5xNgaJpZM4IjUP_
.
Is it really necessary that Butterknife throws an exception when the target object is null while unbinding (throw new IllegalStateException("Bindings already cleared."))? Could it not just do nothing? With the exception thrown I have to catch it always preventively and cannot do anything about it anyway.
I agree with @semaphore3000 . Is there a better way to handle this @JakeWharton