Handling Rotation


Last Updated:

  1. Amon Darthir

    Amon Darthir Active Member This Topic's Starter

    Joined:
    Feb 4, 2010
    Messages:
    27
    Likes Received:
    0
    Hi. I have been working on some apps for a while and I have yet to figure out how to keep my app from resetting each time the screen is rotated. When the screen rotates I want it to just rotate the screen it is on, but instead it rotates and takes you back to the first page. Any help would be wonderful. Thanks
     

    Advertisement
  2. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    If by rotate you mean between landscape and portrait modes, I don't know what you could be doing wrong. Since android 1.5, the rotation is handled automatically by the Android OS. If you are overriding the onOrientationChange() method, then that could be cause your problem.
     
  3. Amon Darthir

    Amon Darthir Active Member This Topic's Starter

    Joined:
    Feb 4, 2010
    Messages:
    27
    Likes Received:
    0
    Here is just a piece of my code. Tried not to put to much in here. Haha. So this is basically what it looks like.
    so each time i go to a new screen i want it when it rotates to rotate that screen but instead it keeps sending me all the way back.
    Sorry its so long
     
  4. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    Ah ok... I see what you are doing. You are changine the content view rather than starting a new activity. This is bad.

    When orientaition is changed, it restarts the activity (essentially at least...), so every time you change the orientation, it is callin onCreate(). Instead of switching view suing setContentView(), you need to create new activities using intents.
     
  5. Amon Darthir

    Amon Darthir Active Member This Topic's Starter

    Joined:
    Feb 4, 2010
    Messages:
    27
    Likes Received:
    0
    oh goody. alright. if i cant figure it out ill be posting again. Thanks for helping me find the problem.
     
  6. Amon Darthir

    Amon Darthir Active Member This Topic's Starter

    Joined:
    Feb 4, 2010
    Messages:
    27
    Likes Received:
    0
    Ok. I think I need help. Can you send me a run through of what I need to do to fix this? Like some sample code or something? Thanks.
     

Share This Page

Loading...