"background activity" on iOS draining battery

Can someone explain to me what “Background Activity” could be when you go to check your battery usage. I can also have “Location” which I believe is the background location updating.

When the AppState changes I kill all subscriptions and all polling functions. There is nothing hitting my server, yet I’m constantly seeing “Background Location”. I don’t have any Google/Facebook/Ad service etc and I can confirm that there are no calls to the server being made (not even sockets open).

Does anyone know what else I can check to see what this “Background Activity” could be?

Managed SDK 40

I found that I was keeping my web socket open. When the app is backgrounded, I now make sure that it is closed.

However I’m still seeing background activity. I only have one background task (the location task). Could that be what it is? I thought that was grouped under “Location” not “Background Activity”.

Well, now I’m completely stumped. I’m killed the websocket connection when the app is backgrounded.

There is literally nothing else running in the background, yet still on iOS the “Background Activity” for the app is running all the time.

@charliecruzan @ide - Is there any documentation anywhere or do you have any suggestions what I can look at? Do expo listeners that get installed via useEffect stay active when the app is backgrounded (like for example Appearance.addChangeListener). Do I need to kill those too on app backgrounding?

I’m not sure the answer to your question but you could try ejecting to a bare RN app on a branch and using Instruments to track energy usage.

Hi @ide, this is all new to me.

What are “Instruments” in this context. Is it a software package?

Where can I learn about if listeners can cause background activity etc. Is there a way for me to see the “background activity” while the app is backgrounded on expo? Maybe something in React dev tools?

Instruments is the Xcode tool for profiling iOS applications: https://help.apple.com/instruments/mac/10.0/#/dev7b09c84f5. It is one of the few tools I know of that can measure power consumption.

Where can I learn about if listeners can cause background activity etc.

In my experience, reading through the React Native source code is the most accurate place to learn how things work.

Ok, I ejected, got the app working with Instruments. However, I still cannot pin point why my app is always has “Background Activity” in backgrounded mode.

Maybe there is a quick list here that I can just run through. For example, after doing some experimenting, I found a few things that persist even when the app is backgrounded:

  1. setInterval (it just keeps going), like if you have a polling function that is constantly running a network call.
  2. Socket connections stay open
  3. Background tasks (I don’t have any besides background location if the user opted for “Always”.

Where else should I look?

Is there a way to run idevicesyslog and just see what’s happening in my app?


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.