【问题标题】:Stop loading admob ads after click点击后停止加载 admob 广告
【发布时间】:2011-11-10 16:56:54
【问题描述】:

我想在用户点击 adview 后停止加载广告我已经实现了 adlistener 并且我把 adView.stopLoading();在 onDismissScreen 上,但是当我关闭广告网页时出现以下错误:

E/AndroidRuntime(1059): java.lang.RuntimeException: Unable to pause activity {ivn.com.teletextinternational/com.google.ads.AdActivity}: java.lang.NullPointerException

代码:

public class MyActivity extends Activity implements OnClickListener, AdListener {
RelativeLayout relativeLayout1;
 ImageView imgpag; 
 FrameLayout frameLayout1;
 FrameLayout frameLayout2;
 Button right;
 Button left;
 ProgressBar probar;
 LinearLayout linear;
 AdView adView;
 EditText numbox;

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    imgpag = (ImageView)findViewById (R.id.imgpag); 
    relativeLayout1 = (RelativeLayout) findViewById(R.id.RelativeLayout1);
    frameLayout1 = (FrameLayout) findViewById(R.id.frameLayout1);
    frameLayout2 = (FrameLayout) findViewById(R.id.frameLayout2);
    left = (Button) findViewById(R.id.left);
    right = (Button) findViewById(R.id.right);
    probar = (ProgressBar) findViewById (R.id.probar);
    adView = new AdView(this, AdSize.BANNER, "a14ebbcd3aae1ff");

    LinearLayout linear = (LinearLayout) findViewById (R.id.linear);
    linear.addView(adView);
    adView.loadAd(new AdRequest());
    adView.setAdListener(this);
 }

public void onDismissScreen(Ad arg0) {
    adView.stopLoading();
            linear.setVisibility(View.GONE);//if you want hide ads
}
}

【问题讨论】:

    标签: android admob adview


    【解决方案1】:

    试试这个吧:

        adView = new AdView(this, AdSize.BANNER, "a14ebbcd3aae1ff");
    

    您创建了一个本地 adView 对象,而不是初始化您的 adView 字段。结果,当您尝试调用 stopLoading() 时,adView 为空。

    【讨论】:

    • 不起作用,我没有收到错误但没有任何反应 adview 仍在加载广告。另外,如果我添加 linear.removeView(adView);我得到了和以前一样的错误
    • 您的用例是您不想再刷新广告,但仍希望它显示?我相信 stopLoading 只是停止加载如果广告已经开始该过程,但我认为 stopLoading 对于插页式广告更有用。至于linear 错误,您在定义局部线性对象而不是初始化线性字段时犯了同样的错误。
    猜你喜欢
    • 2018-02-15
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-17
    • 2019-05-07
    • 1970-01-01
    相关资源
    最近更新 更多