There is an application that in the life cycle on the phases ceases to send data. I think this is related to the life cycle. It interests me when the application is minimized and when the screen is locked, which method is called. Thank.

@Override protected void onPause() { super.onPause(); LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, this); } @Override protected void onStop() { super.onStop(); googleApiClient.disconnect(); } 

    3 answers 3

    In both cases, they will first call onPause, then onStop

    • and tioritic if I change the methods on pause and on stop to connect and receive data, then everything will work in the minimized state? - elik
    • Yes, yes, yes, yes, yes - P. Ilyin
    • @elik No, it will not work correctly, because the onStop method may not be onStop at all. - mit
    • Why can he not volunteer? - P. Ilyin
    • @P.Ilyin because the process will already be killed by the system, for example, because you need to free up resources for other activities. Pay attention to the life cycle map, which is in the answer of Valery Ponomarenko. If you do not take this fact into account in your applications, then a memory leak is guaranteed. - mit

    When the application is minimized or the screen is locked, it is clear that the activity is not currently visible. And if you look at the diagram, then it clearly says "The activity is no longer visible" -> onStop (), therefore, the onStop () method will be called (and, of course, all previous methods).

    Activity life cycle

    • for a full answer (and not just a picture), it would be nice to completely answer the question "when the application is minimized and when the screen is locked, which method is called" - Denis
    • @Denis scheme answers the question asked. When the application is minimized or the screen is locked, it is clear that the activity is not currently visible. And if you look at the diagram, then it clearly says "The activity is no longer visible" -> onStop (), therefore, the onStop () method will be called. - Valery Ponomarenko
    • For clarity, I would explain it in the body of the answer, so that your answer would have more value) - Denis
    • @Denis take note of your comment! :) - Valery Ponomarenko

    About the life cycle of the Activity - you need to understand the following:

    The activation can be destroyed by the system at any time after onPause and, at the same time, the system does not guarantee calling the life-cycle methods that follow onPause .

    Based on this, you need to build a life cycle work plan when activating to the background.