Pending intent always make new activity

后端 未结 6 2148
耶瑟儿~
耶瑟儿~ 2020-12-20 14:51

i trying to make app with nfc function. the problem is when nfc tag discovered, pending intent always make a new activity that already exist. i\'m using tab host. how to mak

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-20 15:19

    Put android:launchMode="singleTask" for your activity (or activities) in the manifest. That does the trick. Whenever an NFC intent is dispatched by the system, always a new Activity will be created. This is unique for NFC intents. So setting android:launchMode="singleTop" will not work, nor will setting flags in the PendingIntent.

    Another solution is to use NfcAdapter.enableForegroundDispatch() in all your Activities. That way your app gets to handle all NFC intents itself directly (via onNewIntent()).

提交回复
热议问题