File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

change the activity orientation depending on the current screen orientation

 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ..
 
Sumit Bisht
Ranch Hand
Posts: 331
Python Ruby Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 485
Android Eclipse IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :
Untitled.jpg
[Thumbnail for Untitled.jpg]
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,
Any ideas?
 
james frain
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic