0

I'm developing an SDK that involves jumping out of the app to others through intents and restoring of the same in memory session. The SDK is initialized using some parameters that are saved as property of an internal static SDKInstance object and used by all the other internal services.

I'm not sure about this design choice though, don't want to save static objects and don't see a reasonable way to provide this data to all other services. Is there some other design pattern I need to be using. Heres some sample code to give an idea.

Public exposed interface:

object SampleSDK {

    fun launchSDK(context: Context, flags: Int? = null, sdkLaunchParams: SDKLaunchParams) {
        InternalSDKInstance.launchSDK(context, flags, sdkLaunchParams)
    }
}

And internal class:

object InternalSDKInstance {

    var sdkParams: SDKParams? = null
        private set // the setter is private (can only be set within this object)

    fun launchSDK(context: Context, flags: Int? = null, sdkLaunchParams: SDKLaunchParams) {
        sdkParams = extractParams(sdkLaunchParams)
    }
}

Wherever some data is required, I use:

InternalSDKInstance.sdkParams?.dataXYZ

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.