Steps:
Fragment
or Activity
onRequestPermissionsResult()
java.lang.IllegalStateException
is thrown: Can not perform this action after onSaveInstanceState
This doesn't happen when I show dialog after some delay(using postDelayed). According to http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html) on post-Honeycomb devices we CAN commit()
between onPause()
and onStop()
without any STATE LOSS or EXCEPTION. Here is a link to sample project source, log file and issue recorded. https://drive.google.com/folderview?id=0BwvvuYbQTUl6STVSZF9TX2VUeHM&usp=sharing
Also I have opened an issue https://code.google.com/p/android/issues/detail?id=190966 but it was marked as WorkingAsIntended and they suggest to just catch exception. But this doesn't solve the issue. I know other ways to solve it, but isn't this android bug?
UPDATE Status fo the bug is again "assigned". Hope it will be fixed soon. My temp solution is
new Handler().postDelayed(new Runnable() { @Override public void run() { // do your fragment transaction here } }, 200);
The bug is accepted and will be fixed, however, I strongly disagree with the postDelayed and timer solutions. The best way to do this would be introducing a state flag in the Activity, in which you set in the callback, and use in onResume or similar. For example:
private boolean someFlag; public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { // some code checking status someFlag = true; }
And then in onResume:
protected void onResume() { if(someFlag == true) { doSomething(); someFlag = false; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With