Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 294
nrofis Avatar asked Oct 20 '22 22:10

nrofis


1 Answers

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

like image 182
Ahmed Ekri Avatar answered Oct 24 '22 01:10

Ahmed Ekri