What is Activity.finish() method doing exactly?

前端 未结 12 1913
别那么骄傲
别那么骄傲 2020-11-22 16:16

I\'m developing android applications for a while, and followed a lot of posts about activity life cycle, and application\'s life cycle.

I know Activity.finish

12条回答
  •  迷失自我
    2020-11-22 16:49

    onDestroy() is meant for final cleanup - freeing up resources that you can on your own,closing open connections,readers,writers,etc. If you don't override it, the system does what it has to.

    on the other hand, finish() just lets the system know that the programmer wants the current Activity to be finished. And hence, it calls up onDestroy() after that.

    Something to note:

    it isn't necessary that only a call to finish() triggers a call to onDestroy(). No. As we know, the android system is free to kill activities if it feels that there are resources needed by the current Activity that are needed to be freed.

提交回复
热议问题