What is Activity.finish() method doing exactly?

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

    In addition to @rommex answer above, I have also noticed that finish() does queue the destruction of the Activity and that it depends on Activity priority.

    If I call finish() after onPause(), I see onStop(), and onDestroy() immediately called.

    If I call finish() after onStop(), I don't see onDestroy() until 5 minutes later.

    From my observation, it looks like finish is queued up and when I looked at the adb shell dumpsys activity activities it was set to finishing=true, but since it is no longer in the foreground, it wasn't prioritized for destruction.

    In summary, onDestroy() is never guaranteed to be called, but even in the case it is called, it could be delayed.

提交回复
热议问题