Problem with admob

我是研究僧i 提交于 2019-12-04 18:41:23

I'm not sure on the exact syntax, could you link the AdMob api?

But your getting an error because when you return the ad layout it is already attached to the previous activity. So you would need something like this:

public static AdView getAdLayout() {

admobView.removeParent(); // or similar see API

return admobView;

}

EDIT

Ah here we go: AdView JavaDoc so it herits from view and RelativeLayout great.

Try this:

public static AdView getAdLayout() {
     if(admobView.getParent() != null){
        admobView.detachAllViewsFromParent();
     }
    return admobView;
}

or

public static AdView getAdLayout() {
     if(admobView.getParent() != null){
        admobView.getParent().removeView(admobView);
     }
    return admobView;
}

The answer is in the JavaDoc just a bit of trial and error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!