Skip to main content
You can add a custom splash Fragment in your application with the Choicely SDK. The splash Fragment can display your branding, animations, or custom logic before the main content loads.

Steps to Add a Custom Splash Fragment

1. Create a Splash Fragment

Create a new fragment that extends AbstractSplashFragment. This is where you’ll define your splash Fragment’s layout and any custom logic.
public class YourSplashFragment extends AbstractSplashFragment {

    @Override
    protected int getLayout() {
        return R.layout.fragment_custom_splash;
    }

    @Override
    protected void onLayoutCreated(@NonNull View layout, @Nullable Bundle savedInstanceState) {
        super.onLayoutCreated(layout, savedInstanceState);
        // Add your custom logic here, like starting an animation or loading data.
    }

    // Set Splash Duration in milliseconds
    @Override
    protected long getSplashDuration() {
        return 1500; // 1.5 seconds
    }
}

2. Create a Splash Factory

Create a factory class that implements ChoicelySplashFactory. This factory is responsible for providing an instance of your custom splash fragment.
import com.choicely.sdk.factory.ChoicelySplashFactory;
import com.choicely.sdk.fragment.AbstractSplashFragment;

public class YourSplashFactory implements ChoicelySplashFactory {

    @Override
    public AbstractSplashFragment makeSplashFragment() {
        return new YourSplashFragment();
    }
}

3. Add the Factory in Your Application Class

Finally, in your Application class (e.g., YourApplication.java or YourApplication.kt), add a call to ChoicelySDK.factory().setSplashFactory() to use your custom splash Fragment.
import android.app.Application;
import com.choicely.sdk.ChoicelySDK;

public class YourApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ....
        ChoicelySDK.factory().setSplashFactory(new YourSplashFactory());
    }
}
Remember to create a layout file named fragment_custom_splash.xml in your res/layout directory to define the visual elements of your splash Fragment, such as an image, text, or a animation view.