Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To get around the illegal state exception issue and essentially implement a dismissAllowingStateLoss() can be done using the following.</p> <pre><code>getFragmentManager().beginTransaction().remove(someDialog).commitAllowingStateLoss(); </code></pre> <p>This should solve the issue without the hacky code. The same can also be applied for show if you have threads communicating through a handler with the UI thread using dialog.show(); Which can cause an illegal state exception as well</p> <pre><code>getFragmentManager().beginTransaction().add(someDialog).commitAllowingStateLoss(); </code></pre> <p><hr> @joneswah is correct, given the posters question. If you are using the support library, replace</p> <pre><code>getFragmentManager() </code></pre> <p>with</p> <pre><code>getSupportFragmentManager() </code></pre> <p><hr> For future Googlers: @Alex Lockwood raises good and valid concerns with this solution. The solution does solve the error and will work in most cases, but hints that there are issues with the approach in the original question, from a UX perspective. </p> <p>The Activity should assume that the async task may not complete and that it will not perform onPostExecute(). Whatever UI action (ie, spinner, ideally not a dialog) is started to notify the user of the async operation, should have provisions to stop automatically either on a timeout or by tracking state and checking in onRestore/onResume type lifecycle events to ensure the UI is updated properly. Services may also be worth investigating.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload