• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps what to do when the screen orientation changes?

aidanmack

Lurker
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?
 
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?
 
Back
Top Bottom