What is the best way to save the instance of my MediaPlayer playing through rotation of the device. I know about the setRetainState() method but I am not using a fragment. What would be the best way to attach the state of my MediaPlayer to the bundle so the music continues to play after the user rotates the device.
Asked
Active
Viewed 56 times
-3
-
Try this solution ..http://stackoverflow.com/questions/10126845/handle-screen-rotation-without-losing-data-android/20279603#20279603 – Bhagwat K May 20 '15 at 06:35
-
1use service. they keep on working in background and doesnt get affected by screen rotation or run in the background even if the user switches to another application. – Sam May 20 '15 at 06:36
1 Answers
-1
Use onConfigurationChanged method of activity to detect Orientation Change
public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}
}
Edit the appropriate element in your AndroidManifest.XML like this to include the android:configChanges

AamirJadoon
- 136
- 1
- 8