In Android when the orientation of a device is changed, activity is destroyed and recreated again (onDestroy() and onCreate() methods are called). If you put your logic into the onCreate() method, i.e. network operation to get some data from the server, then everytime you change the orientation onCreate() will be called and it'll make a costly network request each time. Of course this is not good for performance and user's experience. In order to prevent this you have a couple of options. You can either save your activity's state and then check if the state is changed when the activity is recreated or you can simply put android:configChanges="orientation|screenSize" to your activity in the manifest. Note that most of the solutions in the internet propose to put only orientation however as of Android 3.2 screen size is also changed when device moves from portrait to landscape and omitting it cause your activity to be restarted again. You can check the following link for further information:
http://developer.android.com/guide/topics/resources/runtime-changes.html
that is what I've been looking for... thanks...
ReplyDelete