Hi, I have tested the proposed code and it works. I have mentioned details here: http://erfanonline.blogspot.com/2010/07/android-use-different-orientation-for.html
You can download sample source from there also. Regards Sarwar Erfan On Jul 29, 4:01 pm, Sarwar Erfan <[email protected]> wrote: > Hi, > The problem is, each time orientation is changed, Activity is > destroyed and recreated (that means onCreate is called, later onStart > is called). Now, when you change orientation inside onCreate, then > orientation is changed, activity is recreated again ---> this causes > to onCreate to be called again (and again and again ....) > onCreate is even called before the Activity is shown on the screen. > > I can think of one way around. Get rid of all orientation changing > codes form onCreate and onStart. > Then, before starting an activity, change orientation (if required) > according to the requirement of the activity to be started. > > For example: suppose you need LANDSCAPE for Activity2, then (see how > the condition of if changed) > > //--------------- > if(this.getRequestedOrientation() != > ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { > > this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);} > > //Start Activity2 here > //--------------- > > If you dont want to do as I told above, you need to prevent your > activities from being destroyed and recreated when orientation is > changed. Fortunately, that is possible. > Go to this > link:http://developer.android.com/reference/android/app/Activity.html#Conf... > Quote from the page: > [QUOTE] > In some special cases, you may want to bypass restarting of your > activity based on one or more types of configuration changes. This is > done with the android:configChanges attribute in its manifest. For > any types of configuration changes you say that you handle there, you > will receive a call to your current activity's > onConfigurationChanged(Configuration) method instead of being > restarted. If a configuration change involves any that you do not > handle, however, the activity will still be restarted and > onConfigurationChanged(Configuration) will not be called. > [/QUOTE] > > Regards > Sarwar Erfan > > On Jul 29, 3:21 pm, Robert <[email protected]> wrote: > > > Thanks Sarwar for your answer. But when I put this code into the > > onStart method. The orientation will always be Portrait. > > When I discard the if-part, I am getting the same problem as mentioned > > above. I realized now that, when the app enters the onStart the > > orientation is initally -1(thats why I get the portrait-orientation > > with the if-part). When the setrequestedorientation is called the > > orientation is 0 (LANDSCAPE), as I requested. And then it is in this > > infinite loop and when its now entering the onstart the > > requestedorientation is 1 (PORTRAIT). Which is really weird to me. > > Should I do anything in the TabActivity!? Any suggestions are very > > welcome. > > Thanks > > > On Jul 29, 10:46 am, Sarwar Erfan <[email protected]> wrote: > > > > Hi, > > > Good day. > > > > Change the orientation (call setRequestedOrientation) inside > > > overridden method of onStart, NOT inside onCreate. (do it in both > > > Activity1 and Activity2) > > > > Regards > > > Sarwar Erfan > > > > On Jul 29, 2:25 pm, Robert <[email protected]> wrote: > > > > > Hello, > > > > I have a tabactivity where my app is running in. One of the tabs needs > > > > to have landscape orientation, assume this is activity2, activity1 > > > > needs to have portrait-orientation. > > > > > In activity1 I do have code like: > > > > > public void onCreate(Bundle savedInstanceState) { > > > > super.onCreate(savedInstanceState); > > > > if(this.getRequestedOrientation() == > > > > ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) > > > > > this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); > > > > > } > > > > > And in activity2: > > > > > public void onCreate(Bundle savedInstanceState) { > > > > super.onCreate(savedInstanceState); > > > > if(this.getRequestedOrientation() == > > > > ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) > > > > > this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); > > > > > } > > > > > So when I now want to change from activity1 to activity2. It seems as > > > > my app is in a infinite-loop, it tries to start activity2 again and > > > > again, but it doesnt appear. I dont get an exception either! > > > > > Is that some know bug of android or am I doing something wrong. Help a > > > > appreciated a lot. > > > > > Thanks -- 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

