【问题标题】:Startapp interstitial ad not showing in onCreateStartapp 插页式广告未在 onCreate 中显示
【发布时间】:2013-10-31 18:52:11
【问题描述】:

这是在 onCreate:

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    StartAppAd.init(this, "devID", "appID");
    setContentView(R.layout.activity_results);

    startAppAd.showAd();
    startAppAd.loadAd();
}           

它不显示广告,但如果我将其更改为:

@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);

}

它有效。如何让广告在准备好后立即展示?

【问题讨论】:

    标签: android ads interstitial


    【解决方案1】:

    我通过简单地将loadAd(); 放在上一个活动的onCreate 中并将showAd(); 放在我的startIntent(); 之前解决了这个问题。

    【讨论】:

    • 对不起,我的回答一点帮助都没有。您的解决方法实际上接近推荐的方法。 StartApp SDK 包中包含的 PDF 文档在第 4 页的Example for showing an interstitial ad between activities: 下提到了这一点。这里唯一的问题是您不能开始主要活动之前展示广告(您可能也不想这样做)。解决方法是创建一个没有 UI 且仅用于显示广告和启动主要活动的虚拟启动活动。这是 PDF 的链接:Link.
    • @user2558882 谢谢!我阅读了此 PDF,但我错过了这一点。 Adding Callback when Ad has been shown 也很有用。
    【解决方案2】:

    我在另一篇文章中提到过,尝试将showAd()方法放在loadAd()方法的事件监听器的onReceiveAd()中。

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

    【讨论】:

      【解决方案3】:

      要显示启动应用广告,您必须按照以下步骤操作

      首先声明启动应用ID

      在gradle中先添加这个依赖

      编译'com.startapp:inapp-sdk:3.6.6'

      然后在您的代码中按照您需要的这些步骤进行操作

      私有 StartAppAd startAppAd = new StartAppAd(this);

      在 oncreate 方法中:

          StartAppSDK.init(this, getString(R.string.startAppId), false);
          StartAppAd.disableSplash();
      

      在字符串中你必须传递启动应用程序 ID

      如果你想显示启动画面,那么不要禁用启动画面,只需删除第二行

      如果您想在 backpress 上显示 startapp 广告,请按照此步骤操作

      @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();
      }
      

      如果您想在点击按钮时或在任何情况下显示 startapp 插页式广告,您必须调用此方法:

       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
      
                  }
      
      
              });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-11-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多