I got around the problem by simply putting loadAd();
in the onCreate of the previous activity and showAd();
just before my startIntent();
.
Startapp interstitial ad not showing in onCreate
-
02-07-2022 - |
سؤال
This is in onCreate:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
StartAppAd.init(this, "devID", "appID");
setContentView(R.layout.activity_results);
startAppAd.showAd();
startAppAd.loadAd();
}
And it doesn't show the Ad, but if I change it to:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
StartAppAd.init(this, "devID", "appID");
setContentView(R.layout.activity_results);
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
startAppAd.showAd();
startAppAd.loadAd();
}
}, 2000);
}
It works. How can I make the ad to display as soon as it is ready?
المحلول
نصائح أخرى
I have mentioned in another post, try to put the showAd()
method in the onReceiveAd()
of the event listener of loadAd()
method.
To show start app ads you have to follow these steps
First of all declare start app id
Add this Dependency first in gradle
compile 'com.startapp:inapp-sdk:3.6.6'
after that in your code follow these steps that you require
private StartAppAd startAppAd = new StartAppAd(this);
in oncreate method :
StartAppSDK.init(this, getString(R.string.startAppId), false);
StartAppAd.disableSplash();
in string you have to pass start app id
if you wants to show splash then do not disable splash just remove second line
if you wants to show startapp ad on backpresses then follow this step
@Override
public void onBackPressed() {
StartAppAd.onBackPressed(this);
ExitDialogue();
}
private void ExitDialogue() {
AlertDialog.Builder builder = new AlertDialog.Builder(SampleActivity.this);
builder.setTitle(R.string.account_balance);
builder.setIcon(R.mipmap.ic_launcher);
builder.setMessage("Do you want to exit?")
.setCancelable(false)
.setNeutralButton("More Apps", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=Future+App+Studio")));
}
})
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
SampleActivity.this.finish();
//finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
if you wants to show startapp interstital ad on button click or at any event you have to call this method:
startAppAd.loadAd(new AdEventListener() {
@Override
public void onReceiveAd(Ad ad) {
startAppAd.showAd(new AdDisplayListener() {
@Override
public void adHidden(Ad ad) {
//implement your code here
}
@Override
public void adDisplayed(Ad ad) {
}
@Override
public void adClicked(Ad arg0) {
}
@Override
public void adNotDisplayed(Ad arg0) {
//implement your code here
}
});
}
@Override
public void onFailedToReceiveAd(Ad ad) {
//implement your code here
}
});