Configure the launch screen on the client to display splash ads when users open your app.
The launch screen appears after the app starts and the framework initializes, and disappears when the home page loads. The launch screen ad space is a special, preset ad space. You must first configure the launch screen on the client, and then configure the ad content for the ad space in the console.
Procedure
-
In your project, create an XML page for the launch screen and its corresponding
SplashActivityclass. -
Add the following code to the
MainActivityclass to initialize the launch screen on the home page:@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Home page logic // ........ // ........ // ........ if (SplashActivity.checkIfSplashPrepared()) { startSplash(); } } private void startSplash() { startActivity(new Intent(this, SplashActivity.class)); overridePendingTransition(0, 0); // Remove the transition animation }In this example, a button is added to the app's home page. Clicking this button calls the launch screen.
-
Add the following code to the
SplashActivityclass to display the launch screen:private void doSplash() { final CdpAdvertisementService cdpAdvertisementService = cpdService(); cdpAdvertisementService.doSplash(this, new HashMap<String, String>(), new CdpAdvertisementService.IAdEventHandler() { @Override public void onClosed(SpaceInfo spaceInfo) { } @Override public void onJump(SpaceInfo spaceInfo) { // Jump to the activity target page } }); } public static CdpAdvertisementService cpdService() { CdpAdvertisementService serviceByInterface = LauncherApplicationAgent.getInstance().getMicroApplicationContext().findServiceByInterface( CdpAdvertisementService.class.getName()); return serviceByInterface; } -
Add
SplashActivityto theAndroidManifestfile.You have now configured the launch screen.
What to do next
After you configure the launch screen, create a launch screen ad space in the console. For more information, see Create a launch screen ad space.
Note: An application can have only one launch screen ad space.