-1

If I'm using a one activity multiple fragments design for my app, would the application context in this case be the same as the activity context? I know it's a bad idea to pass the activity context to a ViewModel but in this case is it valid? (The app is always in portrait)

Hadi
  • 119
  • 10
  • 2
    Possible duplicate of [Difference between Activity Context and Application Context](https://stackoverflow.com/questions/4128589/difference-between-activity-context-and-application-context) – Ashish Sep 08 '19 at 15:58

1 Answers1

3

If I'm using a one activity multiple fragments design for my app, would the application context in this case be the same as the activity context?

No. The Application singleton is an entirely separate class.

I know it's a bad idea to pass the activity context to a ViewModel but in this case is it valid?

No — use the Application.

The app is always in portrait

Note that there are many configuration changes, not just orientation. The user can switch locale, enable "dark mode" on Android 10+, enter or leave split-screen mode, resize a Chrome OS window, etc.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491