I'm new to android development and have been making simple apps and in all of them have been making a method called void logic() that I have called at the end of my ViewDidLoad method. logic() contains all of the functionality that my app has. The issue with this is that whenever the screen changes orientation the ViewDidLoad method is re-called and then my app starts as if the application is being opened for the first time. Does anyone know how to do this? This is similar to this question Don't reload application when orientation changes however I do want ViewDidLoad to be re-called when the orientation is changed so that the view is recreated with the new orientation. However I don't want the application to be restarted. Thanks.
Asked
Active
Viewed 58 times
0
-
This link helped me the most: http://www.intertech.com/Blog/saving-and-retrieving-android-instance-state-part-1/ and ...-part-2. – ajb May 27 '14 at 22:36
1 Answers
0
You can use :
@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();
}
}
or
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
And your activity manifest :
<activity android:name=".yourname"
android:configChanges="orientation|keyboardHidden">
</activity>