What is Activity.finish() method doing exactly?

前端 未结 12 1947
别那么骄傲
别那么骄傲 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:35

    My 2 cents on @K_Anas answer. I performed a simple test on finish() method. Listed important callback methods in activity life cycle

    1. Calling finish() in onCreate(): onCreate() -> onDestroy()
    2. Calling finish() in onStart() : onCreate() -> onStart() -> onStop() -> onDestroy()
    3. Calling finish() in onResume(): onCreate() -> onStart() -> onResume() -> onPause() -> onStop() -> onDestroy()

    What I mean to say is that counterparts of the methods along with any methods in between are called when finish() is executed.

    eg:

     onCreate() counter part is onDestroy()
     onStart() counter part is onStop()
     onPause() counter part is onResume()
    

提交回复
热议问题