There is a VideoView that plays video from a web server, here are some example pieces of code:

videoView = (VideoView) findViewById(; videoView.setVideoURI(Uri.parse(sourceUrl)); getWindow().setFormat(PixelFormat.TRANSLUCENT); mediaController = new MediaController(this); mediaController.setMediaPlayer(videoView); videoView.setMediaController(mediaController); videoView.setOnPreparedListener(new OnPreparedListener() { public void onPrepared(MediaPlayer mp) { videoView.requestFocus(); videoView.start();; } }); @Override public void onResume() { super.onResume();; videoView.start(); } @Override protected void onPause() { super.onPause(); videoView.pause(); } 

Actually, if you minimize the program with the home button, then when it expands, it will recreate VideoView and start playing first, do you have any ideas how to fix it? By the way, when you go to sleep from this window and resume everything works fine.

    1 answer 1

    From time to time the system should call the onSaveInstanceState (Bundle) method (you must redefine it). In this method, save your values, such as the position of viewing the video, the position of the scroll, and so on. When the system re-creates your window (this is a regular situation), then by calling the protected void onCreate method (Bundle savedInstanceState) the same intent will be transmitted in the bundle. Now knowledge can be obtained and correctly initialized components.

    If it's good, VideoView should be able to memorize all this by itself, as other elements do, but why it doesn’t ... But in actual fact, you need to save the position, url and maybe loudness.

    Yes, do not forget, the system calls the onSaveInstanceState method usually before the window is minimized, but it can also be called at other times. Therefore you should not make any assumptions about when and why the method will be called.

    • Hmm, in the end it's clear, but does this create a new problem? After all, the call to onCreate, even with progress, will force VideoView to cache a piece of video - AndroidDev
    • Once the user has turned off the application, then he understands what he is doing. The system itself can easily cache and not delete immediately. If you are so scared for traffic, you can manually download the video and then give it a look (or in parallel with the download). Users who watch videos usually either sit on wifi or use unlimited (or with a large margin) traffic. The standard browser also works approximately. But the Youtube application remembers the position, but can not always play - you have to poke a start-stop. - KoVadim