By default, an orientation change will cause the system to destroy and recreate your Activity, to change this behavior change the Activity's entry in AndroidManifest.xml:
<activity android:name=".MyActivity"
android:configChanges="orientation"
android:label="@string/app_name">
which tells Android that you wish handle configurations change yourself, so the Activity will not be restarted when an orientation change occur, but your current Activity instance's onConfigurationChanged() method will be called.
An example of singleton:
public class SingletonObjectDemo {
private static SingletonObject singletonObject;
// Note that the constructor is private
private SingletonObjectDemo() {
// Optional Code
}
public static SingletonObjectDemo getSingletonObject() {
if (singletonObject == null) {
singletonObject = new SingletonObjectDemo();
}
return singletonObject;
}
}
You can check out more info on how orientation change is handled here