1. Download our Official Android App: Forums for Android!

Apps what to do when the screen orientation changes?

Discussion in 'Android Development' started by aidanmack, Jan 12, 2014.

  1. aidanmack

    aidanmack Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Jan 1, 2014

    Jan 1, 2014
    3
    0
    5
    Hi, I have some code in place that checks for if the screen has been re orientated which works fine.
    But its what I do after that that seems to be a pain.

    if I put an if statment in that stops any methods that would normally be trigged on the oncreate method my screen is empty on rotation.

    if I try to just reinflate the view, that doesn't work because I havent saved the data that it displays to singleton.

    It basically seems like I have to save my individual vars to a singleton then if the screen reorientates use them... But then that seems really crude and crappy stuff like if you scroll down the viewlist the position is refreshed to the top when you reorienate..
    What Im doing basically just doesnt seem right?


    Their must be some other easier better way to do this?
     

    Advertisement

  2. houserjr

    houserjr Lurker
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Jan 14, 2014

    Jan 14, 2014
    5
    0
    5
    If you run an app on a phone where the system language is spanish then the strings-es/mystring.xml string file is used if present. If you run an activity and the device is horizontal at the time you run the activity the layout-land/activity_main.xml is chosen if present. well that answers the static part but not really the question. I suggest you research loaders if we are talking database because they dont requery on each orientation change and best practice of MVC design keeping a seperate model java bean separate view activity/xml and so on. Maybe the activity ondestroy() method could be used to save state? Activities run in the UI thread right so we don't need to worry about "race conditions" or singleton?
     

Share This Page

Loading...