开发者

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 s开发者_JAVA技巧till 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜