9

I am facing very strange problem in handling orientation of activity. Let me explain the scenario

I have Activity A and B.Currently A is in landscape mode and B(fixed) is in portrait mode. I am saving state of activity A if user change orientation of A. I went from A (landscape) to B(portrait) so in that case A is in background so it should call onSaveInstance(bundle) method. But it calls and when i come back then A's on Resume() called and i got exception onResume() can not called after onSaveInstance() for A.

This is something , make me annoying.

Update Edit

If both activity can have any orientation. Then activity A onSaveInstance(bundle) does not call while going to B and It works well

Tofeeq Ahmad
  • 11,935
  • 4
  • 61
  • 87
  • 2
    Perhaps this question is relevant to your problem: http://stackoverflow.com/questions/7469082/getting-exception-illegalstateexception-can-not-perform-this-action-after-onsa – David Wasser Dec 13 '12 at 10:22
  • Or this question: http://stackoverflow.com/questions/12450024/can-not-perform-this-action-after-onsaveinstancestate-why-am-i-getting-this – David Wasser Dec 13 '12 at 10:24
  • Thanks ,,these question discuss same issue but no incredible resource while referring to bug. Fragment comes at android version 10 not its running with version 16. So if it were a bug it would have been solved – Tofeeq Ahmad Dec 13 '12 at 10:27
  • And one more thing if it related to fragment transaction then it should be persist in every case. If both activity can have any orientation then it does not persist – Tofeeq Ahmad Dec 13 '12 at 10:28
  • Post your stacktrace and the code from your onResume() please – David Wasser Dec 13 '12 at 10:34
  • No code in onResume(), its just consider them as life cycle. this is my exception i got exception onResume() can not called after onSaveInstance() for A – Tofeeq Ahmad Dec 13 '12 at 10:37
  • Is there a good reason why you cannot paste the text of the exception (including the stacktrace) into your question? With 4,210 reputation points you should know how to do this. You do realize that "i got exception onResume() can not called after onSaveInstance() for A" isn't the exact and complete text of the exception and therefore makes helping you difficult. – David Wasser Dec 13 '12 at 11:26
  • onResume() can not called after onSaveInstance() is exception name only. Thanks for your patience – Tofeeq Ahmad Dec 13 '12 at 11:39

1 Answers1

5

Even though i still waiting for some logical description. But i solved my problem. When you are going from Activity A to B onsaveInstance() of a calls in every case. So when coming back activity restarted but onsaveInstance() does not call again. So i was getting

onResume() can not be called after onSaveInstance(Bundle)

Reason - I think as activity state is already save so it can not called onResume(). And main issue is onSaveInstance(Bundle) is not a part of activity life cycle so its very painful situation.

Solution - I remove super.onSavaInstance(Bundle) from onSaveInstance(Bundle). And problem solved. Its still working for orientation changes

Tofeeq Ahmad
  • 11,935
  • 4
  • 61
  • 87