adamacdo
adamacdo

Reputation: 426

Allow Android app to be garbage collected sooner?

I am writing an app that has audio playing throughout the duration of the app being open. I notice that during my testing phase my battery is draining much faster than without my app on the phone. This may be due to the amount of audio files in the app (the app ends up being 25-35 mb) or the Broadcast Receivers still being registered and taking up some computation power when the app is no longer needed.

My question is (and I know there is no universal "Close App" method) how can I put the entire app on the bottom of the stack, next in line for the garbage collection?

Thanks

Upvotes: 0

Views: 169

Answers (1)

Heiko Rupp
Heiko Rupp

Reputation: 30974

You should have a look at the lifecycle of Android Apps (here for Activity) - when the app goes into background or is no longer visible you should deallocate the broadcast receivers etc and re-register them in onResume.

If your app only has one Activity, you could call finish() to indicate that you don't need it anymore.

Upvotes: 1

Related Questions