androidandroid-lifecycle

Clicking overview(recent) button on android device doesn't call onPause() and onStop() method. Why is that?


I remember that when I used the Android version 9 device before, when I clicked the Overview button, called the onPause and onStop method.

However, these method are not being called on Android 12th version of the device.

  1. Is there any change in Android policy?

  2. How can I call the onPause, onStop when I click the Overview button?


Solution

    1. No
    2. You cannot trigger the onPause() and onStop() methods yourself, these are triggered automatically by the system. According to figure 1 here onPause() is triggered in an activity when another activity moves to the foreground, and onStop() when the activity is no longer visible (applies to both Android 9 and 12). If you press the Recents button, both conditions are met and onPause() and onStop() are triggered in your activity.

    So if you really don't observe onPause() and onStop() in all your apps, then you would have a serious problem with your IDE. Check whether onPause() is triggered after all by adding the third line to the onPause() method and checking the log file to see whether you can find a line with the two specified strings:

    public void onPause() {
      super.onPause();
      Log.i("myAppName", "onPause is starting");
      ... // your code
    }