[android-developers] Re: Force screen orientation and avoid destroy call

2009-08-28 Thread Derek

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



[android-developers] Re: Force screen orientation and avoid destroy call

2009-08-28 Thread Dianne Hackborn
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
-~--~~~~--~~--~--~---



[android-developers] Re: Force screen orientation and avoid destroy call

2009-08-28 Thread Derek

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



[android-developers] Re: Force screen orientation and avoid destroy call

2009-08-28 Thread Dianne Hackborn
Indeed they are not.  The documentation should explain which constants are
appropriate.  The configuration contains an actual orientation, the activity
has a particular orientation *mode* to apply to the activity.

On Fri, Aug 28, 2009 at 10:40 AM, Derek cram.de...@gmail.com wrote:


 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
 
 
 



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



[android-developers] Re: Force screen orientation and avoid destroy call

2009-08-27 Thread Derek

Thanks Mark :-)


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



[android-developers] Re: Force screen orientation and avoid destroy call

2009-08-27 Thread Mark Murphy

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