It seems that constants returned and expected are not the same between ActivityInfo and Configuration. Translating Configuration constants to ActivityInfo seems to solve the problem:
int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_PORTRAIT) initialOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; else if (orientation == Configuration.ORIENTATION_LANDSCAPE) initialOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; Mark, do you think it's OK ? Cheers. On Aug 28, 7:06 pm, Derek <cram.de...@gmail.com> wrote: > Another question: > android:screenOrientation="portrait" locks the screen orientation, > that's fine. > But it is possible to do the same in Activity source code ? (i.e. > removing the screenOrientation in AndroidManifest.xml). > > I've tried the following code to keep the initial orientation but it > fails. > > private int initialOrientation = > Configuration.ORIENTATION_UNDEFINED; > > public void onCreate(Bundle savedInstanceState) { > initialOrientation = getResources().getConfiguration > ().orientation; > ... > } > > public void onConfigurationChanged(Configuration newConfig) > { > super.onConfigurationChanged(newConfig); > setRequestedOrientation(initialOrientation); > } > > I've also tried with: > initialOrientation = getResources().getConfiguration().orientation; > initialOrientation = getRequestedOrientation(); > initialOrientation = getWindow().getWindowManager().getDefaultDisplay > ().getOrientation(); > > Thanks for the help. > > On Aug 27, 9:54 pm, "Mark Murphy" <mmur...@commonsware.com> wrote: > > > > I want my Activity to be always in portrait mode and I do NOT want the > > > onDestroy() method to be called. > > > There are some interesting articles about that at: > > >http://www.androidguys.com/2008/11/24/rotational-forces-part-four/ > > > > The solution seems to be: > > > In AndroidManifest.xml: > > > <activity android:name=".MyActivity" > > > android:screenOrientation="portrait" > > > android:configChanges="keyboardHidden|orientation"> > > > > In Activity code: > > > public void onConfigurationChanged(Configuration newConfig) > > > { > > > super.onConfigurationChanged(newConfig); > > > } > > > > I've tried it and it seems to work. Is there any other alternative or > > > is it the correct solution? > > > Well, I think it's the correct solution. But, then again, I'm biased in > > favor of the author of that fine, upstanding blog post. > > > ;-) > > > -- > > Mark Murphy (a Commons Guy)http://commonsware.com > > Android App Developer Books:http://commonsware.com/books.html > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---