AppContextInitializer
Initializes the AppContext
during the application's startup phase using AndroidX's Initializer
interface.
This class is responsible for setting up the AppContext
by providing the application-wide Context
early in the app's lifecycle. It is designed to work with AndroidX's App Startup
library, which allows you to initialize components as soon as the app starts, without having to modify the Application
class.
Related docu here
Usage:
This class is automatically detected and executed by the
App Startup
library if properly declared in the app's manifest file or through metadata in theAndroidManifest.xml
.It calls
AppContext.setUp()
to initialize theAppContext
with the applicationContext
.The
create()
method returns the global applicationContext
, which can be used for further initialization or passed to other components that require theContext
.Add the related provider in the AndroidManifest.xml file:
<application>
...
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">
<meta-data
android:name="com.tecknobit.equinoxcore.utilities.AppContextInitializer"
android:value="androidx.startup"/>
</provider>
</application>
Implement also the native library (build.gradle.kts):
implementation("androidx.startup:startup-runtime:$version")