7

I have been writing an Android app for several months now. It is not released yet, but it is installed in my device.

Today I got a notification from the Battery Doctor app about my app consuming a lot of CPU, even though I hadn't used it since yesterday.

So basically my app is running on the background, it should not be doing anything, but it is using CPU.

So I opened up TraceView and did some profiling on my app while it was in the background (I did not interact with my app at all during this profiling time) and this is what I got: https://i.stack.imgur.com/t5z9M.png

I am very clueless here. I can see no functions at all from my actual code so I don't even know where to start looking. And I don't really understand what those functions in the screenshot do or why they are showing up there at all.

So I got a couple of questions that I would really appreciate some help with:

  • are my profiling results expected and OK? Or are those functions not supposed to show up if I am not interacting with my app?
  • if those functions are not supposed to show up, can anyone guess what could be wrong in my app? Could admob be the cause?

Thanks a lot!

Jordi Chacón
  • 1,723
  • 1
  • 14
  • 20
  • "Could admob be the cause?" -- temporarily comment out AdMob and see what happens in testing. "Today I got a notification from the Battery Doctor app about my app consuming a lot of CPU, even though I hadn't used it since yesterday." -- have you confirmed this reading using any other tools, particularly ones aimed at software developers? Heck, even **`top`** would help here. – CommonsWare Dec 13 '14 at 01:38
  • Doesn't look bad to me. Your app spends most of the time in MessageQueue pollOnce which means it's waiting for something to happen. Then there are configuration changes (e.g. you've rotated the device) and some drawing related updates (not sure if those should be there if your app is not visible the whole time, maybe? Looks like it's cleaning up) – zapl Dec 13 '14 at 02:09

1 Answers1

0

I have the same issue

See my CPU profile. My app was in background, but the CPU cumsuming always in 1-5%, it will cause battery drain if continue running like this for long time.

enter image description here

Admob?

As @CommonsWare suggestion, I remove admob dependency and run again. The CPU consuming go down to 0% almost time. See new profile: https://i.stack.imgur.com/bMBuL.png (admob SDK version: 17.1.2)

But it is not the solution. I check their sample app, it doesn't have CPU comsuming in background.

I fixed it

If you are using banner ad, you have to call atleast AdView#pause or AdView#destroy in corresponding event of the host activity. Otherwise, the ad view keep checking "Active view", and it causes CPU comsuming.

Khang .NT
  • 1,504
  • 6
  • 24
  • 46
  • Reported to admob sdk team: https://groups.google.com/forum/#!category-topic/google-admob-ads-sdk/android/kdtnVZ0Redk – Khang .NT Jan 02 '19 at 18:09