This ad is used to load and display on the splash screen of an Android application. A splash ad is a full-screen advertisement that appears when the user opens the app, before the main interface is fully loaded.
This function loads a splash screen advertisement within the specified Android activity. The ad is initialized asynchronously, and the provided IKLoadAdListener is used to handle callbacks related to the ad loading process.
fun loadSplashScreenAd(activity: Activity?, listener: IKLoadAdListener?)
Parameters:
activity: The Activity in which the splash ad will be displayed. This can be null if no specific activity context is required at the time of calling.
listener: An implementation of the IKLoadAdListener interface, which will receive notifications about the ad’s load status, including success and failure events.
Sample:
import com.ikame.android.sdk.IKSdkController
import com.ikame.android.sdk.listener.pub.IKLoadAdListener
import com.ikame.android.sdk.data.dto.pub.IKAdError
class SplashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
IKSdkController.loadSplashScreenAd(this, object : IKLoadAdListener {
override fun onAdLoadFail(error: IKAdError) {
}
override fun onAdLoaded() {
}
})
}
}
import com.ikame.android.sdk.IKSdkController;
import com.ikame.android.sdk.listener.pub.IKLoadAdListener;
import com.ikame.android.sdk.data.dto.pub.IKAdError;
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
IKSdkController.loadSplashScreenAd(this, new IKLoadAdListener() {
@Override
public void onAdLoaded() {
}
@Override
public void onAdLoadFail(@NonNull IKAdError ikAdError) {
}
});
}
}
Use the LoadAd and ShowAd functions when you want to preload an ad in a specific state. First, you need to call LoadAd to initiate the ad loading process. Once the ad is fully loaded and you’re ready to display it, call the ShowAd function.
It is important to load the ad beforehand, as ShowAd will run in the background. When you invoke ShowAd, it will automatically wait for the ad to load successfully before displaying it. This ensures a seamless ad experience for the user.
This suspend function displays a splash screen advertisement in the specified activity. It utilizes Kotlin coroutines, allowing the function to be suspended until the ad is either successfully shown or fails. The provided IKShowAdListener is used to receive callbacks about the ad display status.
fun showSplashScreenAd(
activity: Activity?, listener: IKShowAdListener?
)
Parameters:
activity: The Activity where the splash ad will be displayed. This can be null if no specific activity context is needed at the time of showing the ad.
listener: An implementation of the IKShowAdListener interface to handle events related to the ad’s display, such as success, failure, or dismissal.
Return:
Returns a Job? that represents the coroutine handling the ad display process. It can be used to manage the coroutine’s lifecycle or cancel it if needed.
Sample:
import com.ikame.android.sdk.IKSdkController
import com.ikame.android.sdk.listener.pub.IKLoadAdListener
import com.ikame.android.sdk.listener.pub.IKShowAdListener
import com.ikame.android.sdk.data.dto.pub.IKAdError
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
class SplashActivity : AppCompatActivity() {
private var timerWaitAds: Job? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
IKSdkController.loadSplashScreenAd(this, object : IKLoadAdListener {
override fun onAdLoadFail(error: IKAdError) {
}
override fun onAdLoaded() {
}
})
lifecycleScope.launch {
timerWaitAds = IKSdkController.showSplashScreenAd(
this@SplashActivity,
object : IKShowAdListener {
override fun onAdsShowed() {
super.onAdsShowed()
}
override fun onAdsDismiss() {
moveMain()
}
override fun onAdsShowFail(error: IKAdError) {
moveMain()
}
})
}
}
override fun onDestroy() {
super.onDestroy()
timerWaitAds?.cancel()
}
}
import com.ikame.android.sdk.IKSdkController;
import com.ikame.android.sdk.listener.pub.IKLoadAdListener;
import com.ikame.android.sdk.data.dto.pub.IKAdError;
import com.ikame.android.sdk.listener.pub.IKShowAdListener;
import kotlinx.coroutines.Job;
public class SplashActivity extends AppCompatActivity {
private Job timerWaitAds;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
IKSdkController.loadSplashScreenAd(this, new IKLoadAdListener() {
@Override
public void onAdLoaded() {
}
@Override
public void onAdLoadFail(@NonNull IKAdError ikAdError) {
}
});
timerWaitAds = IKSdkController.showSplashScreenAdNor(this, new IKShowAdListener() {
@Override
public void onAdsShowed() {
}
@Override
public void onAdsDismiss() {
}
@Override
public void onAdsShowFail(@NonNull IKAdError ikAdError) {
}
@Override
public void onAdsShowTimeout() {
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
if (timerWaitAds != null) {
try {
timerWaitAds.cancel(null);
} catch (Exception ignored) {
}
}
}
}
This function asynchronously loads and displays a splash screen advertisement within the provided activity. It combines the processes of both loading and showing the ad, making it convenient for developers who want to handle the entire splash ad lifecycle in a single call. The provided IKShowAdListener is used to track the status of the ad display.
This is the method to set a timeout for showing ads. If not set, the timeout time will default to the SDK. When the timeout is enabled, if the ad doesn’t open within the specified time, it triggers a timeout event onAdsShowTimeout.
import com.ikame.android.sdk.IKSdkController
import com.ikame.android.sdk.listener.pub.IKShowAdListener
import com.ikame.android.sdk.data.dto.pub.IKAdError
import kotlinx.coroutines.launch
class SplashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
lifecycleScope.launch {
IKSdkController.setEnableTimeOutOpenAd(true, 60000)// milliseconds
IKSdkController.loadAndShowSplashScreenAd(this@SplashActivity,
object : IKShowAdListener {
override fun onAdsShowed() {
super.onAdsShowed()
}
override fun onAdsDismiss() {
}
override fun onAdsShowFail(error: IKAdError) {
}
override fun onAdsShowTimeout() {
super.onAdsShowTimeout()
}
})
}
}
}
import com.ikame.android.sdk.IKSdkController;
import com.ikame.android.sdk.data.dto.pub.IKAdError;
import com.ikame.android.sdk.listener.pub.IKShowAdListener;
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
IKSdkController.setEnableTimeOutOpenAd(true, 60000);
IKSdkController.loadAndShowSplashScreenAdNonAsync(this, new IKShowAdListener() {
@Override
public void onAdsShowed() {
}
@Override
public void onAdsDismiss() {
}
@Override
public void onAdsShowFail(@NonNull IKAdError ikAdError) {
}
@Override
public void onAdsShowTimeout() {
}
});
}
}