Hi,
I have a specific problem with Android tasks and the NFC foreground
dispatch behavior. My app has a MainActivity with other activities,
which is straightforward. Next to it, I have another activity (I call
it activity B), which can only be launched from a specific URI (in
general launched from the browser). Activity B uses a NFC foreground
dispatch.
Now if I open my MainActivity, switch to the browser, open activity B
and attach a NFC device, a new instance of activity B gets created
instead of onNewIntent() getting called. In the log I find following
message:
startActivity called from non-Activity context; forcing
Intent.FLAG_ACTIVITY_NEW_TASK for: Intent
{ act=android.nfc.action.TECH_DISCOVERED flg=0x20000000 ...}
This message doesn't make sense for me, as I've strictly followed the
documentation. My helper methods for the foreground dispatch look
like:
public void resume(Activity targetActivity) {
nfc = NfcAdapter.getDefaultAdapter(targetActivity);
if (nfc != null && nfc.isEnabled()) {
Intent intent = new Intent(targetActivity,
targetActivity.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent =
PendingIntent.getActivity(targetActivity, 0, intent, 0);
nfc.enableForegroundDispatch(targetActivity,
pendingIntent, null,
new String[][] { new String[] { IsoDep.class.getName() } });
}
}
public void pause(Activity targetActivity) {
nfc = NfcAdapter.getDefaultAdapter(targetActivity);
if (nfc != null && nfc.isEnabled()) {
nfc.disableForegroundDispatch(targetActivity);
}
}
What I don't understand: If I completely close my MainActivity, switch
to the browser, launch activity B and attach a NFC device,
onNewIntent() gets called and everything works as expected.
I would be very happy if someone has a hint for me, because the
current behavior destroys my workflow.
Thanks for the help.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en