You can use an Application
context which is provided by the AndroidViewModel
, you should extend AndroidViewModel
which is simply a ViewModel
that includes an Application
reference.
More Related Contents:
- Dagger 2 injecting Android Application Context
- What is ‘Context’ on Android?
- When to call activity context OR application context?
- Using Application context everywhere?
- What’s the difference between the various methods to get an Android Context?
- Difference between Activity Context and Application Context
- Dialog throwing “Unable to add window — token null is not for an application” with getApplication() as context
- How to get package name from anywhere?
- Calling startActivity() from outside of an Activity context
- What’s “tools:context” in Android layout files?
- Using getResources() in non-activity class
- Android ViewModel additional arguments
- getApplicationContext(), getBaseContext(), getApplication(), getParent()
- getting context in AsyncTask
- How to set up DAGGER dependency injection from scratch in Android project?
- Why does AlertDialog.Builder(Context context) only accepts Activity as a parameter?
- get Context in non-Activity class [duplicate]
- Dagger 2.10 Android subcomponents and builders
- Why getApplicationContext() in constructor of Activity throws null pointer exception?
- Get context inside onClick(DialogInterface v, int buttonId)?
- Implementing a simple Dagger2 sample
- Why a viewmodel factory is needed in Android?
- Cannot create an instance of class ViewModel
- Set dynamic base url using Retrofit 2.0 and Dagger 2
- Android: ProgressDialog doesn’t show
- Android : References to a Context and memory leaks
- Getting the Application Context
- Use of Context to start another Activity
- android – How to get view from context?
- How do you override a module/dependency in a unit test with Dagger 2.0?