I understand that apps on my iPhone can harvest my private usage data for things like advertising, selling my data, etc… Is that data only collected while actively using the app, or can it also be collected while the app remains closed and not in use?
iOS generally allows apps to perform background tasks for several minutes after closing - to wrap up any proccessing, file writing, network transmission, etc, they were in the middle of before closing. So yes, an app can leak your private data while not actively in use as the foreground app.
Additionally, some apps can be given background activity permissions to keep running in the background (things like music players, navigation/mapping apps, etc) and those also could be leaking your private data while backgrounded.
An app can only do anything with the data you give it access to. It can’t collect new data while it’s closed.
If it’s running in the background it can collect data but only if you’ve given it permission. For example you might give an execrable app permission to record your heart rate, number of steps etc.