Does onDestroy() or finish() actually kill the activity?

限于喜欢 提交于 2019-11-30 14:32:29

The finish() kills the activity and releases memory... unless you have some reference stored that is leaked... for example on methods like onRetainNonConfigurationInstance()

When you press the back button what is called is the finish() method that than calls onPause, onStop, onDestroy.

The default behavior is that back button will cause the activity to exit and it'll be destroyed. Displaying a toast in onDestroy or onPause is not a good idea though. It'll alter the lifecycle the of your activity in a way you don't want it to happen. Use logging instead, so you'll see what's really happening. BTW, finish() is something that you call explicitly from your code and onDestroy() is a lifecycle event/method which gets called as a result of finishing/destoying the activity in any way.

Finish() will literally finish your activity and if no references are present a GC will recover resources. onDestory() is actually a method that the system will call when it is destroying your activity and you are supposed to implement this function. You dont need to worry avout destroying your app , android does it for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!