This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Android and the fly likes change the activity orientation depending on the current screen orientation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "change the activity orientation depending on the current screen orientation " Watch "change the activity orientation depending on the current screen orientation " New topic
Author

change the activity orientation depending on the current screen orientation

Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

Hi Guys ,
Is there a way to let Android OS handles the my Activity orientation automatically ? for instance if the screen orientation now is landscape so the Activity will be landscape and if it changed the activity changes too ..


Thanks,
Sherif
Sumit Bisht
Ranch Hand

Joined: Jul 02, 2008
Posts: 329

From the Android SDK reference
"Unless you specify otherwise, a configuration change (such as a change in screen orientation, language, input devices, etc) will cause your current activity to be destroyed, going through the normal activity lifecycle process of onPause(), onStop(), and onDestroy() as appropriate. If the activity had been in the foreground or visible to the user, once onDestroy() is called in that instance then a new instance of the activity will be created, with whatever savedInstanceState the previous instance had generated from "

So, you can specify any orientation related task at onCreate() method of your activity itself.
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

Sumit Bisht wrote:From the Android SDK reference
"Unless you specify otherwise, a configuration change (such as a change in screen orientation, language, input devices, etc) will cause your current activity to be destroyed, going through the normal activity lifecycle process of onPause(), onStop(), and onDestroy() as appropriate. If the activity had been in the foreground or visible to the user, once onDestroy() is called in that instance then a new instance of the activity will be created, with whatever savedInstanceState the previous instance had generated from "

So, you can specify any orientation related task at onCreate() method of your activity itself.

i found this too, but when i tried it always go to landscape mode!! see the attachments,

here is my code :


[Thumbnail for Untitled.jpg]

Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

Guys,
Any ideas?
james frain
Ranch Hand

Joined: Apr 06, 2011
Posts: 36
I posted on Stack Over flow too about this.
activity.setRequestedOrientation( 1 ) in your create method ( or indeed in a unit test )
does diddly squat, the orientation will always be 0, ie landscape, it seems the only way to get the orientation to change is to run it on a physical device.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: change the activity orientation depending on the current screen orientation
 
Similar Threads
how to add a scrollbar to a view
Application crashes
Change the Printer Orientation??
HoneyComb 3.0 Orientation Issues
Linking sequence diagram,