Does Android NFC Android Manager have a bug?

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()) {
        // nfc is the default NFC adapter and never null on my devices

        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!

+3
2

IntentFilter[] IntentFilter[] . , NFC, , - IntentFilter (s) . , , NFC .

- , :

IntentFilter[] iFilters = new IntentFilter[2];
iFilters[0] = new IntentFilter();
iFilters[0].addAction("android.nfc.action.TECH_DISCOVERED");
iFilters[1] = new IntentFilter();
iFilters[1].addAction("android.nfc.action.TAG_DISCOVERED");
iFilters[1].addCategory(Intent.CATEGORY_DEFAULT);

enableForegroundDispatch.

UPDATE: . , Android , . , , :

  • B ,
  • NFC, , Activity A B.

- 2. SINGLE_TOP : Activity B A. A , , Activity B , .

, Android ( ), , , Android, . , - .

: B launchMode "singleTask" ( "singleInstance" ). B (3-) .

+2

, : Main → Detect tag → Activity Activity → Writer activity Detect tag → Write tag

, ( , , ) (, ), .

, , : Writer Detect tag → Write tag

- . , laucnhes , , .

startActivity(new Intent(this,MyTagWriterActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

→ → -NEW_TASK- > Writer →

, .

0

All Articles