Just call setRequestedOrientation().  onConfigurationChanged() is a really
bad place to do this though -- you'd typically do it in onCreate().

Note that the transition to your app will be much better if you can specify
the orientation in the manifest, since that way the system knows what
orientation to switch in to before it starts launching your app.

On Fri, Aug 28, 2009 at 10:06 AM, 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
> >
>


-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to