getting exception “IllegalStateException: Can not perform this action after onSaveInstanceState”

前端 未结 30 2811
迷失自我
迷失自我 2020-11-22 05:12

I have a Live Android application, and from market i have received following stack trace and i have no idea why its happening as its not happening in application code but it

30条回答
  •  离开以前
    2020-11-22 05:53

    I was always getting this when I tried to show fragment in onActivityForResult() method, so the problem was next:

    1. My Activity is paused and stopped, which means, that onSaveInstanceState() was called already (for both pre-Honeycomb and post-Honeycomb devices).
    2. In case of any result I made transaction to show/hide fragment, which causes this IllegalStateException.

    What I made is next:

    1. Added value for determining if action I want was done (e.g. taking photo from camere - isPhotoTaken) - it can be boolean or integer value depending how much different transactions you need.
    2. In overriden onResumeFragments() method I checked for my value and after made fragment transactions I needed. In this case commit() was not done after onSaveInstanceState, as state was returned in onResumeFragments() method.

提交回复
热议问题