2

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 = new 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!!

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Sith
  • 105
  • 1
  • 4
  • 11
  • https://stackoverflow.com/questions/456211/activity-restart-on-rotation-android check that savedInstanceState and this keyword might help – alkanschtein Oct 08 '17 at 15:25

2 Answers2

5

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"/>
hooked82
  • 6,336
  • 4
  • 41
  • 46
  • What you mean "and call onCreate again on orientation or keyboard changes" ?by the way, whats happen after Orientation change?! onCreate and onResume Call? – Dr.jacky Nov 01 '12 at 06:00
1

you should add the following line in each of your activity Element in android menifest file

 android:configChanges="orientation|keyboard|keyboardHidden" 
Shah
  • 4,990
  • 10
  • 48
  • 70