On Tue, Jun 7, 2011 at 12:56 AM, janoti <[email protected]> wrote: > I have an Activity. I am running a new thread from onCreate which is > creating a socket. > When the device goes from portrait to landscape mode or vice-versa the > Activity is getting restarted. > I have different UI (xml) file for portrait and landscape mode. > Creating a new socket every time and connecting to to Network, > degrades the performance.
Then don't do that. Either have the socket be managed by a Service, or pass the socket (and the thread that's using it, if relevant) to the new activity via onRetainNonConfigurationInstance(). > To solve this problem I set this flag in manifest file > [android:configChanges="keyboardHidden|orientation"] > and override "onConfigurationChanged" in my activity. You did not "solve this problem" (hint: you missed most of the configuration changes) and created more problems for you (hint: you now have to manually manage every resource from your Java code). > I have to do setContentView inside onConfigurationChanged for changing > the UI. and setting up my UI again. This is one manifestation of the "created more problems" that I mentioned above. > I just wanted to know is it the right thing I am doing or there are > better alternatives for this type of problems. Either have the socket be managed by a Service, or pass the socket (and the thread that's using it, if relevant) to the new activity via onRetainNonConfigurationInstance(). -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy _Android Programming Tutorials_ Version 3.4 Available! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

