Continue activity after screen orientation change - Android
i currently have a class that'll play audio Files, however if i tilt my screen to horizontal or portrait, it just restarts. How can i make my app continue from where it left off after i tilt my screen? Note that i do not want my app to be fixed in the portrait/horizontal position.
Public void Play(){
AudioRenderer mr = 开发者_如何学JAVAnew AudioRenderer();
mp = mr.AudioRenderer(filePath);
}
private class AudioRenderer extends Activity {
private MediaPlayer AudioRenderer(String filePath) {
File location = new File(filePath);
Uri path = Uri.fromFile(location);
mp= MediaPlayer.create(this, path);
}
return mp}
Thanks a lot!!
You can accomplish this by setting an attribute on your activity in your AndroidManifest.xml file. This tells your activity to not kill the activity and call onCreate again on orientation or keyboard changes
<activity android:name="YourActivity" android:configChanges="orientation|keyboardHidden"/>
you should add the following line in each of your activity Element in android menifest file
android:configChanges="orientation|keyboard|keyboardHidden"
精彩评论