There is a good Google webpage on this @ Handling Runtime Changes. This covers when user changes screen between horizontal/vertical view, and switching applications. Code snippet:
@Override
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();
}
}
The code above can be placed in the Activity or the Fragment subclass.
In your manifest xml, you set:
<activity android:name=".MyActivity"
android:configChanges="orientation">
Please keep us posted, I would like to know of your progress. Someday I may want to do this also. And I would code it like this, if I do