2

I want to handle orientation in my android app by implementing onSaveInstanceState. I add all the variables that I need to the bundle in the onSaveInstanceState method and everything is ok and I can restore them in the onCreate method of the same fragment.

The problem is although I can restore all the variables, getActivity() has null value.

I tried adding setRetainInstance(true) but in this case I couldn't restore the saved variables from bundle.

can anyone help me? Thanks,

user4232
  • 592
  • 1
  • 12
  • 37
Saeid Farivar
  • 1,667
  • 24
  • 43
  • 1
    [This answer](http://stackoverflow.com/a/10854067/1521536) helped me out. It's not straight to your question but I hope it'll help… –  Jul 28 '12 at 04:24
  • 2
    this solution worked for me:http://stackoverflow.com/questions/7951730/viewpager-and-fragments-whats-the-right-way-to-store-fragments-state the problem was I was creating new instance of the fragments which is not the right way. also I am no longer using setRetainInstance(true) – Saeid Farivar Jul 30 '12 at 20:19
  • 2
    Thanks. I think you can answer and accept the answer yourself, to help other people reading your question. –  Jul 30 '12 at 20:55

1 Answers1

0

This solution worked for me:viewpager-and-fragments-whats-the-right-way-to-store-fragments-state the problem was I was creating new instance of the fragments which is not the right way. also I am no longer using setRetainInstance(true) –

Community
  • 1
  • 1
Saeid Farivar
  • 1,667
  • 24
  • 43