Note that there are some explanatory texts on larger screens.

plurals
  1. POTwo activities with NFC foreground dispatch issue
    primarykey
    data
    text
    <p>I have two activities A and B. A always starts before B and B uses the dialog theme (this is required and important). Both use the NFC foreground dispatch mechanism, which works pretty well. However, when the orientation changes there is an issue. I enable and disable the foreground dispatch in the onResume and onPause methods, as I should.</p> <p>What happens:</p> <ul> <li>A launches, A onResume gets called</li> <li>A onPause, B launches, B onResume gets called (everything as expected and it works)</li> <li>Orientation change</li> <li>B onPause gets called, B launches again, B onResume gets called, A launches in the background again, A onResume gets called, A onPause gets called</li> </ul> <p>--> Now B's foreground dispatch doesn't work anymore.</p> <p>B's dialog theme is causing this issue as everything works well with a normal theme. Is there a workaround?</p> <p><strong>Solution:</strong></p> <p>Thanks for the comments, but I found a workaround, which helps. In the onCreate method of activity B I do the following:</p> <pre><code> /* * This workaround is needed as this activity uses the dialog theme. When the background activity uses the foreground * dispatch as well, then it breaks this activity's foreground dispatch on an orientation change. */ mCancelButton.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { NfcForegroundDispatch.setupForegroundDispatch(NfcDetectorActivity.this); } }); </code></pre> <p>As I've said, it's a workaround not a solution.</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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