Initialization - Fragment Standard Experience

Embed the SDK in your own Activity as a Fragment, keeping your Activity lifecycle uninterrupted.

Fragment Standard Experience Initialization

The PayMitto SDK can run inside your own Activity as a Fragment, instead of launching a new Activity. This is the recommended approach when you need your Activity to remain in the RESUMED state while the SDK is running, for example when you have coroutines, LiveData observers, or custom modals tied to your Activity's lifecycle.

Fragment initialization is a two step process. First you configure the SDK, then you create the Fragment:

  1. Call configureFragment with your PayMittoConfiguration object. This prepares the SDK internals and your authentication provider. It returns right away and does not start authentication.
  2. Call createFragment to get the Fragment, then add it to your FragmentManager. Authentication runs inside the Fragment, which shows the SDK loading view while it signs in and then presents the flow.
PayMitto.configureFragment(
    activity = this@MainActivity,
    payMittoConfiguration = sdkConfiguration
)

val fragment = PayMitto.createFragment()
supportFragmentManager.beginTransaction()
    .replace(R.id.container, fragment)
    .addToBackStack(null)
    .commit()

ℹ️

Call configureFragment first

createFragment needs the SDK to be configured. Always call configureFragment before createFragment, otherwise the SDK throws an IllegalStateException.


Hosting the Fragment with navigation

Because createFragment returns the Fragment right away, you can also let the navigation system build it for you. Call configureFragment before navigation reaches the SDK destination, usually in your Activity's onCreate.

With the Navigation Component (XML nav graph), declare the SDK Fragment as a destination:

<fragment
    android:id="@+id/paymitto_sdk"
    android:name="com.paymitto.android.sdk.internal.PayMittoFragment" />

With Compose Navigation, host it through AndroidFragment from androidx.fragment:fragment-compose:

PayMitto.configureFragment(
    activity = this@MainActivity,
    payMittoConfiguration = sdkConfiguration
)

setContent {
    NavHost(navController, startDestination = "sdk") {
        composable("sdk") {
            AndroidFragment<PayMittoFragment>()
        }
    }
}

ℹ️

Edge-to-edge

When using the Fragment API, your Activity is responsible for calling enableEdgeToEdge() if you want the SDK visuals to extend behind the system bars.


ℹ️

Locale

In Fragment mode, display strings follow your host Activity's locale. The localization parameter in PayMittoConfiguration still controls the API request language (Accept-Language header) and date formatting.


ℹ️

After process death

The SDK internals do not survive the process being killed. When the system restores your Activity, call configureFragment again before the Fragment is recreated, or detect that the SDK is not configured and route the user to a safe screen. This matters most with navigation graph hosting, where the navigation system recreates the Fragment on its own.


ℹ️

If you are using Jetpack Compose

Don't create the configuration object or call PayMitto.configureFragment and PayMitto.createFragment in the compose scope, since recompositions lead to runtime errors.

Create the configuration object inside a remember clause or in an AndroidX ViewModel, and call configureFragment before setContent.



Did this page help you?