Why is my Android app using CPU in the background?

2k Views Asked by At

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!

1

There are 1 best solutions below

1
On

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.