Android: Releasing resources in onDestroy(); method
I understand that the system may kill the activity without calling onDestroy(). Say I have a MediaPlayer that runs even when it's not visible, I would 开发者_如何学Cbe releasing the player in onDestroy() method.
Now, if the system decides to kill the activity after calling onPause() and never called onDestroy(), what does it mean for my MediaPlayer? Is it ever released? This is bigger problem for Camera since I think it requires to be released for other activities to use it.
It is very very rare that you should keep media playing from an activity after onPause(). You most certainly should release it as it will create leaks. Instead your media should be playing in a Service that doesn't have the onPause() issues (a service is either running or not) and then your activity interfaces with the service.
精彩评论