1

I have this situation.

  1. A drawer layout -> each section is a fragment
  2. A section contain a page viewer (3 fragments )
  3. Each fragment contains a recyclerview and each item is a fragment

I have some problems.

  1. When the orientation of the screen changes i move always to the first fragment of the page adapter.

  2. If i write something in one of these fragments and the sceeen orientation change lose everything.

  3. Same problems with onPause etc. How can I manage this situation? thanks.

BPeter_24
  • 71
  • 9

3 Answers3

0

Make sure the you are using getChildFragmentManager() instead of getFragmentManager()/getSupportFragmentMAnager() inside a nested Fragment.

Abhishek V
  • 12,488
  • 6
  • 51
  • 63
  • yes i use getChildFragmentManager but what should i do if for example i am in the second page of page viewer in the 5th element. I rotate the screen and the activity will destroy and after recreate. So, How can i say well, i was in the second page and inside the 5th element? – BPeter_24 May 14 '15 at 13:35
0

Maybe it's will be helpful. Just paste it in your AndroidManifest file

android:configChanges="orientation|keyboardHidden|screenSize"
Aleksandr Gorshkov
  • 473
  • 1
  • 6
  • 16
-1

Add this android:configChanges="keyboardHidden|orientation|screenSize"> inside activity of your AndroidManifest.xml and adding this to every fragment is working fine for me.

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }else{
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
}
Exigente05
  • 2,161
  • 3
  • 22
  • 42