I have an annoying problem with the behavior of the foreground manager. Sometimes, instead of calling, onNewIntent()it completely recreates activity that disrupts the application’s workflow.
My specific situation : Activity A is a MainActivity that uses the foreground manager. Everything works as it should. However, in my activity B launched from a browser (VIEW action), the foreground manager no longer works under certain circumstances.
The working process:
I launch MainActivity, switch to the browser (without closing MainActivity), start activity B and attach my NFC device → it creates a new activity B.
I start MainActivity and close it again. After that, I switch to the browser, start activity B and attach my NFC device → everything works withonNewIntent()
The code is correct, for example. if I connect the NFC device in the first scenario twice, it works as it should, the second time, but not the first time. In MainActivity and Activity B, I finally call the disableForegroundDispatch () method in the onPause () method.
Is there a solution for my specific problem? It sounds like a mistake to me.
Edit:
public void resume(Activity 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) {
if (nfc != null && nfc.isEnabled()) {
nfc.disableForegroundDispatch(targetActivity);
}
}
These methods are called in the corresponding methods in each action. Thanks for the help!
Solution: After a very long study, I finally found a problem. Logcat printed:
- startActivity called from a context with no activity; forced Intent.FLAG_ACTIVITY_NEW_TASK for: Intent
Stackoverflow, NotificationManager, . singleTask B , , , , .
MainActivity, . MainActivity , . , , B ? .
, NFC!