与AdMob的问题 [英] Problem with admob
问题描述
OK,我曾问过类似的<一个href="http://stackoverflow.com/questions/5408336/a-common-footer-for-an-entire-application-android">question已经得到了前一个答案,但认为过于笼统的问题。
OK, I had asked a similar question before and had got an answer but that was too general a question.
现在我有一个应用程序,其中有大量的活动。每个活动已被列入其布局文件相同的AdMob(AD浏览报)布局。现在的问题是,当我从一个活动到另一个后的第一个屏幕完成加载广告,第二个活动仍在等待另一则广告中提取周期发生[即,它再次发送广告请求,并显示一个新的广告]。所有我想做的事是我的应用程序,以显示在每一个活动的广告相同的实例。 [相同的实例意思是:我有一个基于时间间隔上的广告必须刷新,所以一个新的广告请求必须在期限届满,而不是当用户从一个活动导航到另一个只发送]
Now I've an app in which there are plenty of activities. Each activity has the same admob (AdView) layout being included in its layout file. Now the problem is when I go from one activity to the other after the first screen has finished loading the ad, the second activity still waits for another ad fetch cycle to happen [ie., it again sends an ad request and displays a new ad]. All I want to do is for my app to show the same instance of the ad in every activity. [Same instance meaning: I have a time interval based on which the ads must refresh, so a new ad request must be sent only when the time limit expires, not when user navigates from one activity to another.]
有反正我可以做到这一点。我曾在前面的解决方案中提到的单身的做法,但也有很多的并发症COS每次我这样做,它说,指定的孩子已经有一个家长和调用removeView父是必要的。
Is there anyway I can do this. I have tried the "Singleton" approach mentioned in the earlier solution but there are lot of complications cos everytime I do that, it says that the specified child already has a parent and a call to removeView on the parent is necessary.
难道我做错什么(或/和)任何人可以帮助我做一些其他的解决办法?
Am I doing anything wrong (OR/AND) can anybody help me with some other solution??
我的Singleton类是在这里:
My Singleton class is here:
public class CommonAdFooter {
static final CommonAdFooter commonAdFooter = new CommonAdFooter();
static AdView admobView;
LayoutInflater LInflater;
private CommonAdFooter() {
LInflater = (LayoutInflater) Constants.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
admobView = (AdView) LInflater.inflate(R.layout.ad_layout, null);
LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
admobView.setLayoutParams(lp);
}
public static AdView getAdLayout() {
return admobView;
}
}
这是我的广告布局文件
and this is my layout file for the ads
<?xml version="1.0" encoding="utf-8"?>
<com.admob.android.ads.AdView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myapp="..."
android:id="@+id/ad" android:layout_alignParentBottom="true"
android:background="#C9E3F6" android:layout_width="fill_parent"
android:layout_height="wrap_content" myapp:backgroundColor="#006699"
myapp:primaryTextColor="#C9E3F6" myapp:secondaryTextColor="#C9E3F6" />
编辑:Admob的 API 链接添加
推荐答案
我不知道确切的语法,你能链接AdMob的API?
I'm not sure on the exact syntax, could you link the AdMob api?
但是,你得到一个错误,因为当你返回的广告版面它已经连接到previous活动。所以,你需要这样的:
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:
<打击>公共静态AD浏览报getAdLayout(){击>
<打击> admobView.removeParent(); //或类似的见API 击>
<打击>返回admobView; 击>
<打击>} 击>
修改的
啊在这里我们去: AD浏览报的JavaDoc 所以从视野和herits < A HREF =http://developer.android.com/reference/android/widget/RelativeLayout.html相对=nofollow> RelativeLayout的的伟大。
Ah here we go: AdView JavaDoc so it herits from view and RelativeLayout great.
试试这个:
public static AdView getAdLayout() {
if(admobView.getParent() != null){
admobView.detachAllViewsFromParent();
}
return admobView;
}
或
public static AdView getAdLayout() {
if(admobView.getParent() != null){
admobView.getParent().removeView(admobView);
}
return admobView;
}
答案是在JavaDoc只是有点试验和错误
The answer is in the JavaDoc just a bit of trial and error
这篇关于与AdMob的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!