What is the difference between onPause() and onStop() of Android Activites?

后端 未结 8 1147
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 07:33

From android doc here http://developer.android.com/reference/android/app/Activity.html, it said \'Activity comes into foreground\' will call onPause(), and \'Ac

相关标签:
8条回答
  • If you can still see any part of it (Activity coming to foreground either doesn't occupy the whole screen, or it is somewhat transparent), onPause() will be called. If you cannot see any part of it, onStop() will be called.

    A dialog**, for example, may not cover the entire previous Activity, and this would be a time for onPause() to be called.

    **I am not referring to an Android Dialog here, rather a conceptual idea of something that pops up and only obscures part of the user screen. This note was added to clarify based on a comment from @GMsoF below

    0 讨论(0)
  • 2020-12-02 08:10

    I faced many problems with onPause and onStop methods and hence I will clear three scenarios that I came across-
    1. When you click on the recent app button, no life cycle method is called but the onWindowFocusChanged(boolean hasFocus) is called with hasFocus value passed as false. In android version before 5 , onPause method used to get called, on pressing the recent app button.

    2. When a pop up like activity appear over your activity, as mentioned by Malcolm, the onPause button is called. If new activity that takes up the whole screen is called, then onStop is called on previous activity. Android permission dialog also cause your activity to call onPause.

    3. If screen times out on your activity, then onPause is called. After sometime if you will not open the screen then onStop will be called.

    Also one important thing mentioned by the ateiob that completes the answer

    A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager). A stopped activity also retains all state and member information, but is no longer attached to the window manager


    Hope it helps.

    0 讨论(0)
提交回复
热议问题