[英]android live wallpaper: how to destroy adview?
My problem that my live wallpaper displays some ad in the settings screen in a linearlayout (it works perfectly), but when I send it to background (eg: press home button), it seems that the adview is not destroyed and that causes higher cpu usage (25-50%). 我的动态壁纸的问题是在设置屏幕上以线性布局显示一些广告(效果很好),但是当我将其发送到背景(例如:按下主屏幕按钮)时,似乎该广告视图没有被破坏并且导致更高的cpu用量(25-50%)。 If I turn off my internet connection or just remove the ad displaying code it works without spinning.
如果我关闭了互联网连接,或者只是删除了广告显示代码,它就不会旋转。 After I investigated the question, I found ( https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals ) that I had to destroy the adview at onDestroy, but my problem is that this should happen in the activity where I can't reach the adview.
对问题进行调查后,我发现( https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals )必须销毁onDestroy上的adview,但是我的问题是这种情况应该在无法达到广告浏览量的活动。 And I don't know how I could solve it so if you have any idea please help me.
而且我不知道该如何解决,所以如果您有任何想法请帮助我。 My code: AdPreference.java:
我的代码:AdPreference.java:
public class AdPreference extends Preference {
public AdPreference(Context context, AttributeSet attrs, int defStyle) {super (context, attrs, defStyle);}
public AdPreference(Context context, AttributeSet attrs) {super(context, attrs);}
public AdPreference(Context context) {super(context);}
public AdView adView;
@Override
protected View onCreateView(ViewGroup parent) {
// this will create the linear layout defined in ads_layout.xml
View view = super.onCreateView(parent);
// the context is a PreferenceActivity
Activity activity = (Activity)getContext();
// Create the adView
adView = new AdView(activity, AdSize.BANNER, "mybanner");
((LinearLayout)view).addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
adView.loadAd(request);
return view;
}
and my activity: public class Prefs extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener { 和我的活动:公共类Prefs扩展了PreferenceActivity实现了SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.wallpaper_settings);
}
@Override
protected void onDestroy()
{
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
}
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
{
} }
I could be wrong because I am not the best at this, but it looks like you might be missing a 我可能错了,因为我不是最擅长的事情,但是看起来您可能会错过
@Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
Or something like that. 或类似的东西。 I mean, I don't see really anywhere that you tell the live wallpaper to stop the ad requests.
我的意思是,您告诉动态壁纸停止广告请求的地方真的看不到。
Like I said, I could be wrong, but those are my beliefs on the matter at hand. 就像我说的那样,我可能是错的,但这是我对当前问题的信念。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.