1

I want keep activity and use different layout (landscape or portrait) when rotate screen.

  • layout (portrait) : there 3 textview, one is visible and other textview is gone
  • layout-land : there 3 textview and all is visible

Followed best answer from here >> Activity restart on rotation Android , I put

android:configChanges="keyboardHidden|orientation|screenSize"

on my manifest and i put this code :

  @Override
    public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      setContentView(R.layout.myLayout);
    }

efect before put above code : Activity and data is keeped but cannot change screen layout land/portrait

after put above code : Activity is keeped, layout is changed, but data is lost

so how to solve it ?

Community
  • 1
  • 1
Amay Diam
  • 2,561
  • 7
  • 33
  • 57

1 Answers1

0

When you write this:

android:configChanges="keyboardHidden|orientation|screenSize"

You are telling the system you will handle the rotation change yourself and so it doesnt do automatic stuff it usually do like saving the data through viewing mode change.

There is no need for this line, just create another layout directory with a resource qualifier "land", the dir should be named "layout-land" and put in it the layout you want the app to have in landscape mode and the data will be saved through the change.

Like so:

enter image description here

Ignore the contents of the directories in the image.

TomerZ
  • 615
  • 6
  • 17