0

So as we know these methods will be called when orientation change in Activity.

onPause() -> onSaveInstanceState() -> onStop() -> onDestroy() -> onCreate() -> onStart() -> onRestoreInstanceState() -> onResume()

So we can see the onDestroy() method is called.

If the ViewModel() is lifecycle aware then how come the viewmodel is not cleared and preserving the data?

Balaji
  • 1,773
  • 1
  • 17
  • 30

1 Answers1

2

Being lifecycle-aware doesn't mean that ViewModel has the same lifecycle with Activities/Fragments. onClear() method is called when an Activity finishes (and a Fragment is detached).

There's a nice graph comparing Activitie's and ViewModel's lifecycle in this documentation