Medet
Medet

Reputation: 123

Keep ViewModel alive even though there is no screen rotation

It's well known that on screen rotation activity will be recreated and we need to survive configuration changes if we follow the MVP or MVVM patterns to keep alive Presenter or ViewModel(Example: to avoid double calls to WebAPIs). The question is, do I need to keep alive my ViewModel or Presenter if by business requirement we don't have screen rotations(only portrait mode)? Thanks a lot in advance.

Upvotes: 3

Views: 515

Answers (1)

ernazm
ernazm

Reputation: 9268

Short answer: Yes, you do.

Long answer: Orientation change is one of possible configuration change events, there are others (like Locale change, hardware Keyboard open/hide, screen size change (due to enable/disable Split Mode) etc.).

Moreover, configuration change is one of possible causes of activity's recreation - it can be re-created w/o configuration change by the system when the activity is in background and system goes low on memory. You can simulate this with "Don't keep activities" developer option enabled.

Upvotes: 4

Related Questions