Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

android - AdMob banners cause high CPU usage

I have the latest AdMob version (6.4.1), and when I show some banner its cause my CPU to start sweating (Not to mention the battery :S ).

I am destroying the AdView when I leave the activity, but when the activity is started it takes about 20% of CPU usage.

Is there any way to fix it? Why the CPU usage is so high when the ads are shown?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Having test my app with 2 different implementations of AdMob I found that implementing it via java code and not XML is match lighter for the app.

Update No1:

You can also add custom listeners to destroy after some time and recreate in order to handle it even better. Serverside there is also a parameter telling the app ad how soon should ask for a new ad, I am not sure if it exist in all cases but it is there for DFP accounts.

A nice suggested way to implement the ad is that:

new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
  if (!isBeingDestroyed) {
      final AdRequest adRequest = new AdRequest();
      final AdView adView = (AdView) findViewById(R.id.ad);
      adView.loadAd(adRequest);
  }
}).sendEmptyMessageDelayed(0, 1000);

also do not forget to call adView.destroy() onDestroy() activity or when you do not want it any more!

The above way is mentioned here with many useful memory releases!

the complete answer is here: https://stackoverflow.com/a/14683378/1932105

please use the search next time. Good luck


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...