4

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?

Alexandre Khoury
  • 3,896
  • 5
  • 37
  • 58

3 Answers3

1

I got around the problem by simply putting loadAd(); in the onCreate of the previous activity and showAd(); just before my startIntent();.

Alexandre Khoury
  • 3,896
  • 5
  • 37
  • 58
  • 1
    Sorry that my answer didn't help at all. Your workaround is actually close to the recommended approach. The PDF document included in the StartApp SDK package mentions this on page 4 under `Example for showing an interstitial ad between activities:`. The only problem here is that you cannot show the ad _before_ starting the main activity (and you probably don't want to either). Workaround for that would be to create a dummy splash activity that has no UI and only serves to show the ad and start the main activity. Here is the link to the PDF: [Link](http://ge.tt/6jvjpWy/v/0?c). – Vikram Nov 12 '13 at 02:15
  • @user2558882 Thanks! I read this PDF but I missed that point. Also `Adding Callback when Ad has been shown` is very useful. – Alexandre Khoury Nov 12 '13 at 15:27
1

I have mentioned in another post, try to put the showAd() method in the onReceiveAd() of the event listener of loadAd() method.

https://stackoverflow.com/a/31959288/3835769

Community
  • 1
  • 1
Neerkoli
  • 2,423
  • 3
  • 16
  • 21
1

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

            }


        });
Najaf Ali
  • 1,433
  • 16
  • 26