There is an activit in which in onCreate I call a fragment of the video player. In the fragment there are methods:

  @Override public void onResume() { onResume(); //Воспроизвел видео } @Override public void onPause() { onPause(); //Остановил видео } 

Further there are such programs for the release of the OP. For example, a task manager. I clicked to stop the process, stopped, but onDestroy does not work either in the activation or in the fragment. Accordingly, it turns out I start the program again, and first the old fragment goes, and from the bottom it is new, and the video starts to play two. Link to the old player has already been lost. How to make onDestroy work?

    1 answer 1

    No Calling the onDestroy() method is not guaranteed. Rebuild the application logic.

    • And how then to be if everything is not released then there will be a memory leak. Any ideas how to rebuild? - Ivan
    • I tried to swear onStop saying that after the saverinstance the fragment cannot be deleted. I add the fragment as add on onCreate as add, but if I use replace, everything is ok. Is this not a mistake and will it not cause any leaks? - Ivan
    • @Ivan will not. With the add() method, you add another fragment to the container. The replace() method replaces one fragment with another. The execution of the onStop() method is also not guaranteed by the system. The last (and first) guaranteed closure method is onPause() - pavlofff
    • Then replace and the system will release the previous fragment by itself. - Ivan