DroidLearner
DroidLearner

Reputation: 2135

Android: How to return back to previous activity when video is stopped playing?

video

I'm playing video from raw folder. Generally once its completed it remains in same activity. how to return back to previous activity automatically without pressing back button?

Upvotes: 3

Views: 2468

Answers (3)

Alex MDC
Alex MDC

Reputation: 2456

Are you using a VideoView to play the video in your 2nd activity? If so, you can use the OnCompletion event to call finish() on the activity, which will return you to the 1st activity.

Something like this should work:

VideoView videoView = (VideoView) findViewById(R.id.videoView);
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
    public void onCompletion(MediaPlayer player) {
        Log.i("VideoView", "onCompletion()");
        finish();
    }
});

Just be sure to replace R.id.videoView with the actual id in your layout file.

Hope that helps!

Upvotes: 4

RajeshVijayakumar
RajeshVijayakumar

Reputation: 10650

After playing a video onCompletion() method is invoked, in that just call finish() method in it.

Upvotes: 2

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132992

Use MediaPlayer.OnCompletionListener to Listen when Video Playing in finished in Activity 2 and start Previous activity on onCompletion as :

 videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
    {
        @Override
        public void onCompletion(MediaPlayer mp)
        {
             //start Previous Activity here

            Current_Activity.this.finish();
        }
    }); // video finish listener

Upvotes: 2

Related Questions