Possible Duplicate:
Handling Screen Orientation - Android
In my application i am having a listview with list of songs and a button with play/pause option. how to handle screen orientation while playing a song. help me with samples...........
Possible Duplicate:
Handling Screen Orientation - Android
In my application i am having a listview with list of songs and a button with play/pause option. how to handle screen orientation while playing a song. help me with samples...........
http://developer.android.com/training/basics/activity-lifecycle/recreating.html#SaveState Simply get the position of player in onSaveInstanceState and save it. When orientation changed and activity recreated. Load track in MediaPlayer and in onRestoreInstanceState check if position was saved previously if yes set MediaPlayer position
What do you want to do? By default when your app's screen is rotated that activity will be restarted. If you want to avoid this altogether you could add android:configChanges="keyboardHidden|orientation
to the activity in your manifest file. You'd then want to override the onConfigurationChanged
method to actually watch for a configuration change and change any UI stuff you need.
Another option you have is to use the application class. From Activity restart on rotation Android, Depending on what you're doing in your initialization you could consider creating a new class that extends Application and moving your initialization code into an overwridden onCreate method within that class.
public class MyApplicationClass extends Application {
@override
public void onCreate() {
super.onCreate();
// TODO Put your application initialization code here.
}
}
Hope that helps. See that link for more info.