0

I have this activity that I use to play videos.

public class OtherActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_other);
        VideoView view = (VideoView) findViewById(R.id.videoView1);
        view.setMediaController(new MediaController(this)); 
        view.setVideoURI(Uri.parse("http:somevideo.mp4"));  
    }
}

And here is my layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
        <VideoView
            android:id="@+id/videoView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerInParent="true"/>
</RelativeLayout>

Now, the problem here is that whenever I rotate the device the video goes back to the beginning. How can I stop this?

spacitron
  • 2,095
  • 7
  • 30
  • 39

3 Answers3

0

Your activity is simply restarting when it rotates. This is default behavior of Android.

Document yourself about android rotations and configChanges.

Community
  • 1
  • 1
shkschneider
  • 17,833
  • 13
  • 59
  • 112
0

To make a device rotation a configuration change add the following code to the <activity> tag in the AndroidManifest.xml.

android:configChanges="orientation|screenSize"

Note: The device configuration is a set of characteristics that describe the current state of the device. The characteristics that make up the configuration include screen orientation, screen size, language and others.

Lavekush Agrawal
  • 6,040
  • 7
  • 52
  • 85
0

I think this will be happened on activity restart.

Please add below line in activity tag of AndroidMainfest.

 <activity
        android:name="com.test.MainActivity"
        android:configChanges="orientation|screenSize">
  ..........
  ..........
  </activity>
Hashir Sheikh
  • 1,811
  • 1
  • 14
  • 14