2

When would one justify adding this to manifest.xml?

android:configChanges="orientation|keyboardHidden|screenSize"

Thankyou

Luke Allison
  • 3,118
  • 3
  • 24
  • 40

2 Answers2

1

Adding this to the manifest means that you will control what happens when orientation changes, keyboard is minimized, screen size changes. If you do not add this then the onCreate gets called again on these events.

But say you have a different layout for landscape and portrait. Then you would like to call onCreate again to render the landscape layout.

suku
  • 10,507
  • 16
  • 75
  • 120
  • Would you mind looking at the code in this question and telling me if it is possible to avoid using android:configChanges="orientation|keyboardHidden|screenSize" ? – Luke Allison Mar 14 '16 at 06:57
  • http://stackoverflow.com/questions/35941585/avoiding-manually-handling-configuration-changes – Luke Allison Mar 14 '16 at 10:32
1

Yes its required based on your requirement. I had an app in which we had to show videos on orientation change the video would restart hence i had to overide the onConfigureation() method and handle it, As i said it depends on your requirement

Aniruddha K.M
  • 7,361
  • 3
  • 43
  • 52
  • Would you mind looking at the code in this question and telling me if it is possible to avoid using android:configChanges="orientation|keyboardHidden|screenSize" ? http://stackoverflow.com/questions/35941585/avoiding-manually-handling-configuration-changes – Luke Allison Mar 14 '16 at 06:57
  • sure, could you post the code here in SO and also give exact specifics of the problem – Aniruddha K.M Mar 14 '16 at 06:58
  • Amazing. I added some details to clarify what the exact issue is at the link above. Would you mind downloading the code from the GitHub link? There is a bit too much relevant code to post to a SO page and the inter dependencies will be easier to understand in Android Studio. Let me know either way. – Luke Allison Mar 14 '16 at 07:07
  • Basically, if the configuration attribute is removed from the manifest the fragment listener is lost. I need a way to retain it. – Luke Allison Mar 14 '16 at 12:00
  • 1
    retain your fragment and reinstantiate it in on saved instance state like this http://stackoverflow.com/questions/12640316/further-understanding-setretaininstancetrue – Aniruddha K.M Mar 14 '16 at 12:03
  • Thanks for the link. I have added the java code of the project to my question. Could you please point to where I should add setRetainInstanceState() etc. from your link? I use a ViewPager so it is a little different to their example. There isn't any user input to ItemListFragment so I'm assuming that means there's no need to use saveInstanceState or am I wrong? – Luke Allison Mar 15 '16 at 00:20
  • Studying the fragment lifecycle daily is killing me! – Luke Allison Mar 16 '16 at 03:28
  • @LukeAllison i was not able to understand the issue, could you please elaborate it in 2-3 crisp, brief points as the whole paragraph in the other question eludes me – Aniruddha K.M Mar 16 '16 at 05:27
  • Sorry, I literally just finished rewording it. In summary, ( 1 ) I create a PageFragmentListener called mListener in the newInstance method of ItemListFragment ( 2 ) When rotating the screen, ItemListFragment is destroyed and recreated but mListener is not recreated ( 3 ) After clicking on an item in the list the setOnClickListener in onBindViewHolder() checks if mListener is null before attempting to call mListener.onSwitchToNextFragment() ( 4 ) This causes a null pointer exception – Luke Allison Mar 16 '16 at 05:36
  • @LukeAllison the project works fine if we remove the line from the manifest i double checked it. in which fragment is that listener there – Aniruddha K.M Mar 16 '16 at 05:49
  • Are you sure? This video shows the sequence of events that take place in the LogCat included in the SO question. http://sendvid.com/dzdecjjf – Luke Allison Mar 16 '16 at 05:58
  • positive buddy try removing it – Aniruddha K.M Mar 16 '16 at 06:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/106418/discussion-between-war-hero-and-luke-allison). – Aniruddha K.M Mar 16 '16 at 06:01