AppContext
object AppContext
Utility object that manages the application's Context
across the app lifecycle.
The AppContext
object allows for safe access to the application's global Context
throughout the app. It ensures that the Context
is initialized properly before being used by other components, preventing potential issues like null pointer exceptions or uninitialized access.
Usage:
Call
setUp(context: Context)
once, typically in theonCreate()
method of theApplication
class, passing the applicationContext
.Access the application
Context
anywhere in the app usingAppContext.get()
, but only aftersetUp()
has been called. If you attempt to callget()
before setup, an exception will be thrown.
Throws
if the Context
is accessed before initialization via setUp
.