0

I have been searching about fragments for days. I could not find any example or question about my case. In my case, orientation change and saving state is so important.

In the app, there will be many steps. For each step, there will be a fragment on portrait mode. User will sliding on them for next step. But on the landscape mode, all steps will be on only one screen.No sliding. When orientation changes, states should be saved. During the using application the user will change orientation anytime he/she wants.

Can anyone give me example about this?

My current approach is like that: For portrait: Many fragments For landscape: Only one fragment and this is not one of portrait fragments.

MSr
  • 288
  • 1
  • 6
  • 14
  • One question at a time, please (I proposed edit to remove your second question). Fragments have a lifecycle simiar to Activities, so you can use the same onPause/onResume overrides to save your state as you're used to from Activities. – 323go Mar 10 '14 at 14:05
  • Please see this link which explains one method of retaining your data during orientation change. http://stackoverflow.com/questions/11160412/why-use-fragmentsetretaininstanceboolean – Kuffs Mar 10 '14 at 14:14
  • @323go I edited my question. Yes I know fragment lifecycle. But the main problem is to show all fragments in one screen for landscape mode. I mentioned about it because I did not want anybody give me example with state loss. – MSr Mar 10 '14 at 14:14
  • 1
    Have you considered creating a folder in the res folder like (layout-port) and placing your layout there for portrait mode and then placing landscape layout in the regular layout folder? – Eenvincible Mar 10 '14 at 14:17
  • @Eenvincible yes I tried that. But I could not save states. – MSr Mar 10 '14 at 14:19

1 Answers1

0

you can create a folder in the res folder and have a layout for portrait mode and another for landscape mode.

As for saving data, see OnSavedInstanceState and OnRestoreInstanceState these methods are called when the screen is flipped, so if you have data you must save it in OnSavedInstanceState and then recover it in OnRestoreInstanceState.

Ricky
  • 258
  • 2
  • 11