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 the AndroidManifest.xml.

  • It calls AppContext.setUp() to initialize the AppContext with the application Context.

  • The create() method returns the global application Context, which can be used for further initialization or passed to other components that require the Context.

  • 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")

See also

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open override fun create(context: Context): Context

Initializes the AppContext with the application-wide Context.

Link copied to clipboard
open override fun dependencies(): List<Class<out Initializer<*>>>

Specifies dependencies for this initializer.