2

In my application there have one activity (MainActivity)and four fragment . when my app goes in splitView (Multi Window mode) the onCreate() method get called in MainActivity and that reason first fragment get loaded when i goes to multiWindow mode. How to stop recalling onCreate() method when app goes in splitView.

ankuranurag2
  • 2,300
  • 15
  • 30

1 Answers1

2

To avoid calling onCreate() and onDestroy() method in activity when application goes on MultiWIndow mode (SplitView) write android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation" in Manifest file.

  • This will also prevent recreating when switching between landscape and portrait. Generally you're better off correctly implementing saved state and have the activity recreated. Handling config changes manually makes sence for fullscreen activities such as camera, gallery or games. – Eugen Pechanec Feb 05 '19 at 10:54
  • I don't know your code, but if your fragment is reloaded every time then rewrite it like so `if (savedInstanceState == null) { supportFragmentManager.beginTransaction() ... }`. This will only setup your fragment once. You don't have to change manifest. – Eugen Pechanec Feb 05 '19 at 10:56