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

后端 未结 8 1172
隐瞒了意图╮
隐瞒了意图╮ 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条回答
  •  挽巷
    挽巷 (楼主)
    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.

提交回复
热议问题