When I rotate my phone, my Activity restarts. I have a video view playing video, I rotate and the video restarts. Now I found adding this to my activity in the manifest fixed it
<activity android:name="Vforum" android:configChanges="orientation"></activity>
The problem now is the video controls aren't being redrawn until they disappear and come back, thus leaving either really long controls going from landscape to portrait mode or really short controls going from portrait to landscape. Once they disappear and then I tap to make them come back, then they are correctly sized. Is there a better 开发者_StackOverflow社区method of doing this?
add
android:configChanges="orientation"
to your Activity in AndroidManifest.xml.
- solved my issue won't download progressive video again..
If your target API level 13 or higher, you must include the screenSize
value in addition to the orientation
value as described here. So your tag may look like
android:configChanges="orientation|screenSize"
Consider remembering video file position in Activity lifecycle events. When Activity is created you could obtain video position and play it from the moment it was restarted.
In your Activity class:
@Override
protected void onCreate(Bundle bundle){
super.onCreate(bundle);
int mPos=bundle.getInt("pos"); // get position, also check if value exists, refer to documentation for more info
}
@Override
protected void onSaveInstanceState (Bundle outState){
outState.putInt("pos", myVideoView.getCurrentPosition()); // save it here
}
Adding the configChanges
attribute to your manifest means that you will handle config changes yourself. Override the onConfigurationChanged()
method in your activity:
int lastOrientation = 0;
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks if orientation changed
if (lastOrientation != newConfig.orientation) {
lastOrientation = newConfig.orientation;
// redraw your controls here
}
}
ConfigChanges is right, but it did work like this;
<activity
android:configChanges="orientation|screenSize" ... >
and also in the Activity Class
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (lastOrientation != newConfig.orientation) {
lastOrientation = newConfig.orientation;
// redraw your controls here
}
}
You Should try this. Go to your AndroidManifest.xml file then past it tag.
<activity android:name=".activity_name"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
精彩评论