High bar usage with admob

I am trying to advertise inside my application. According to Admob Documentation I need to initialize the SDK mobile ads

MobileAds.initialize(this, "YOUR_ADMOB_APP_ID"); 

This causes a splash when using high-level use in code.

enter image description here

But if I delete this line, the usage time is exchanged, and this line of code does not seem to affect the placement of ads inside the application.

enter image description here

Also, when requesting an ad from using admob ram again pops up and triggers 3-4 GC events when the application starts. I believe this is a memory leak.

Here, as I request an ad in the onCreate method

 AdRequest request = null; if (BuildConfig.DEBUG) { //Facebook Audience Network List<String> testDeviceId = new ArrayList<>(); testDeviceId.add("TESTID");//Redmi Note 3 testDeviceId.add("TESTID");//Moto G 1st Gen AdSettings.addTestDevices(testDeviceId); //Google Ad-mob request = new AdRequest.Builder() .addTestDevice("TESTID")//Redmi Note 3 .addTestDevice("TESTID")//Mot G 1st Gen .build(); } else { request = new AdRequest.Builder() .build(); } AdView mAdView = findViewById(R.id.adView); mAdView.loadAd(request); 

When you load these banner ads, you get several GC events. If I don't load ads, the GC event never kicks.

enter image description here

Is this behavior normal with admob? How can i solve this?

+5
source share
6 answers

Google AdView has a WebView with lots of animation inside. It will heat the entire mobile processor. AdView takes up 30% of the processor.

Decision. . You can also add custom listeners for destruction after a while and recreate to deal with it even better. Serverside also has a parameter showing the applicationโ€™s advertisement, how soon a new advertisement should be requested, Iโ€™m not sure that it exists in all cases, but it exists for DFP accounts.
here is the easiest way to suggest

 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); 

Here is a link that provides a complete solution for this.

Hope this helps you.

+1
source

Yes, this behavior is normal. AdView is a dynamic WebView that consumes about 50 MB of RAM. Most memory leaks occur when you rotate the screen, and an instance of a previous operation is bound to an element, like a listener or thread. The following are examples. To check if the application is not leaking or not, you can use LeakCanary or Android Studio.

To check for leaks in Android Studio

  • Run memory profiler
  • Select Memory and Dump Java Heap
  • Export file to .hprof file
  • Drag and drop the .hprof file into Android Studio and find the Analyzer tasks and click the run button to check if your activity is losing.
0
source

Your application is still within the acceptable RAM limit for most devices.

0
source

Note High memory usage - AdMob on Android (55 MB) available in Google Groups regarding the use of High Ram Admob

0
source

You can put android:largeHeap="true" in your AndroidManifest.xml file so that your users are not affected.

0
source

I donโ€™t know if this will help, but if you are not indifferent to using ram and you use advertising in many actions, you can run the advertising gangs from the application class, in which case the ad will be initialized only once

-1
source

Source: https://habr.com/ru/post/1274866/


All Articles