3

There is a lot of questions about how we can overcome change in the orientation of the screen. Because as you all may know when we rotate a screen then the whole activity is recreated and unexpected results occur.

One solution that seems to fix this is to add this to the activity tag from the manifest:

 <activity
     android:configChanges="orientation|screenSize" >
 </activity>

My question

If the above solution allows the activity to be rotated without recreation, then why do we have to worry about this issue? Why should we care about stuff like Architecture Components?

Thanks.

EDIT

I will edit the idea behind the question so future viewers understand what I mean.

If I did use the above in all my activities then should I expect everything to overcome the change in the screen orientation(ex: switch from portrait to landscape and vice versa).

example:

I am paginating a list of items each time I reach the top of my list, then suddenly I change to landscape...Then does this mean that adding the above in the manifest won't restart my list to the default items(so that I have to paginate all over again).

  • there are many situations where you can't fix it just with this line, and have to handle it correctly. But you can't just ask for a list of this situations. If you face any problems - ask question about them. – Vladyslav Matviienko Apr 19 '18 at 07:08
  • @VladyslavMatviienko when does it fix it? And when it doesn't? can you give an example, so I understand what you mean? –  Apr 19 '18 at 07:10
  • 1
    the most common case is when you need different layouts for landscape and portrait. – Vladyslav Matviienko Apr 19 '18 at 07:11

1 Answers1

2
  • You might need to show a different layout based on the orientation and the screen size of the device that you are running your application.
  • You might have to recreate the activity on your own need so that you can reorganize the data showing in a screen based on the screen size.
  • In case of showing only one layout for your application without considering the screen rotation, you might just put android:screenOrientation="portrait" or android:screenOrientation="landscape" to get rid of the situations where you handle the changes for your screen orientation.

There are other use cases where you need to handle the orientation of the screen.

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
  • But my question is does the above solution fix all the issues that have to do with screen orientation of activity? –  Apr 19 '18 at 07:19
  • Does it always survive the screen orientation? –  Apr 19 '18 at 07:19
  • Why people are making an issue of this. If we can handle it with a single line in manifest.....single line causes the activity not to be recreated? Why its a big deal? –  Apr 19 '18 at 07:23
  • That is what I answered in my question. There are several places where you need to change the presentation of your application screen based on the device rotation. This is an usual case when you are developing sophisticated android application which looks good in all devices. – Reaz Murshed Apr 19 '18 at 07:25
  • So if I add the above to the manifest and rotate my device, then nothing will be recreated? –  Apr 19 '18 at 07:29
  • like showing a progress dialog and rotate the screen? then nothing will be recreated. –  Apr 19 '18 at 07:30
  • Why don't you just check that for yourself? Please check and report if there's anything seems strange from your perspective. – Reaz Murshed Apr 19 '18 at 09:37
  • I checked and upon rotation nothing seemed to change....I am asking to know if I can use this solution in production app. –  Apr 19 '18 at 09:38
  • Surely you can. – Reaz Murshed Apr 19 '18 at 09:39
  • I am thankful for your effort and help....But I have to ask for the last time using the above solution, means that upon change of screen orientation (ONLY SCREEN ORIENTATION) my app wont be recreated? and thus I dont have to worry about saved instance sate and stuff like that..... –  Apr 19 '18 at 09:42
  • @database, no worries. I am really very happy to help you. Yes, you are right about the activity not being recreated on orientation change if you have the configuration above. If you want this in each of your activities in your project, then add the configuration for all in the manifest. Thus you do not have to be worried about saving the instance state. – Reaz Murshed Apr 19 '18 at 09:49
  • Great to know that I could help! – Reaz Murshed Apr 19 '18 at 10:21