Android,android官網

來源:互聯網
上載者:User

Android,android官網
IllegalStateException: Can not perform this action after onSaveInstanceState


本文地址:http://blog.csdn.net/caroline_wendy


參考:http://stackoverflow.com/questions/7469082/getting-exception-illegalstateexception-can-not-perform-this-action-after-onsa/10261438#10261438
解釋:This is the most stupid bug I have encountered so far. I had a Fragment application working perfectly for API < 11, and Force Closing on API > 11.I really couldn't figure out what they changed inside the Activity lifecycle in the call to saveInstance, but I here is how I solved this :
@Overrideprotected void onSaveInstanceState(Bundle outState) {    //No call for super(). Bug on API Level > 11.}

I just do not make the call to .super() and everything works great. I hope this will save you some time.
EDIT: after some more research, this is a known bug in the support package.If you need to save the instance, and add something to your outState Bundle you can use the following :
@Overrideprotected void onSaveInstanceState(Bundle outState) {    outState.putString("WORKAROUND_FOR_BUG_19917_KEY", "WORKAROUND_FOR_BUG_19917_VALUE");    super.onSaveInstanceState(outState);}


EDIT2: this may also occur if you are trying to perform a transaction after your Activity is gone in background. To avoid this you should use commitAllowingStateLoss()
EDIT3: The above solutions were fixing issues in the early support.v4 libraries from what I can remember. But if you still have issues with this you MUST also read @AlexLockwood 's blog : Fragment Transactions & Activity State LossSummary from the blog post (but I strongly recommend you to read it) :
NEVER commit() transactions after onPause() on pre-Honeycomb, and onStop() on post-HoneycombBe careful when committing transactions inside Activity lifecycle methods. Use onCreate(), onResumeFragments() and onPostResume()Avoid performing transactions inside asynchronous callback methodsUse commitAllowingStateLoss() only as a last resort.



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.