https://kotlinlang.org logo
#android
Title
# android
a

Anastasia Finogenova

06/10/2020, 1:08 PM
Hi everyone a question, I don't think it is mentioned in the docs anywhere. When overriding ViewModel's onCleared is calling super.onCleared() required and what are possible consequences of not calling it , does anyone know?
g

Giorgos Neokleous

06/10/2020, 1:20 PM
Source Code seems like no consequences. Looks like a default implementation to prevent users from stubbing it out.
z

zalewski.se

06/10/2020, 1:22 PM
So the easiest would be just to check the sources 🙂 There you can notice that
onCleared()
is empty inside and its being called at the end of
clear()
method. So it’s just a callback to clear your own subscriptions.
a

Anastasia Finogenova

06/10/2020, 1:24 PM
@zalewski.se I did that , but then I checked other lifecycle super calls like onViewCreated etc and they are also all empty
But as we know they are required and that mentioned In the docs so not sure what's up there
i

Ian Lake

06/10/2020, 3:05 PM
Methods should be explicitly marked as
@CallSuper
if you need to call super
super.onViewCreated()
has never been a required call, hence why it doesn't have
@CallSuper
a

Anastasia Finogenova

06/10/2020, 3:06 PM
Ah ok I see it in onCreate for example
i

Ian Lake

06/10/2020, 3:06 PM
If you find any exceptions to that, please file a bug
👍 1
a

Anastasia Finogenova

06/10/2020, 3:06 PM
Thanks!