Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have two activities and I use android:configChanges="keyboardHidden|orientation|screenSize"

 @Override
      public void onConfigurationChanged(Configuration newConfig) {
          super.onConfigurationChanged(newConfig);
        setContentView(R.layout.activity_main);
          if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {

          } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {

          }
      }

One active use for portrait to landscape orientation of the second but when the orientation changes, activity is loaded and data is lost

How can I save the data and change the activity orientation?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
251 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you have small data, you can save and restore it using onSavedInstanceState and onRestoreInstanceState .. for details go through this link Saving data

But in case, you have large data then I must say, you should not allow for the orientation changes(which force your activity to recreate). You can restrict it by adding below line in manifest file :

android:configChanges="orientation|keyboardHidden" // fixes orientation

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...