0

I implemented an app using NFC which has URL link. So, When NFC is on, the mobile detects URL and opens my app.

I made it happen like this:

<activity
    android:name=".view.main.MainActivity"
    android:launchMode="singleTop"
    android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="android.nfc.action.NDEF_DISCOVERED" />
        <action android:name="android.nfc.action.TECH_DISCOVERED" />
        <!--<action android:name="android.intent.action.MAIN" />-->

        <!--<category android:name="android.intent.category.LAUNCHER" />-->
        <category android:name="android.intent.category.DEFAULT" />

        <data
            android:host="example.com"
            android:scheme="http" />
    </intent-filter>

    <meta-data
        android:name="android.nfc.action.TECH_DISCOVERED"
        android:resource="@xml/nfc_tech_filter" />
</activity>

However, the problem is, I have many activities and fragments. It works even while I use my application and It keeps open my application on each and every activities and fragments.

I don't want this behaviour. I want it detects URL just out of my application. How can I achieve this behaviour?

c-an
  • 3,543
  • 5
  • 35
  • 82

1 Answers1

1

make it single task to avoid multiple opening of the activity

android:launchMode="singleTask" 

also read this doc maybe help you

Alireza Sharifi
  • 1,127
  • 1
  • 9
  • 18
  • I think it just uses single process. But It still detects `deeplink`. Is there any better way to avoid Deeplink? – c-an Jun 21 '19 at 06:37
  • If explain exactly the case that you want to avoid it , i will help you to figure this out. I think I don’t know exactly what you trying to do and what is the case that make many activities to open. – Alireza Sharifi Jun 21 '19 at 16:41
  • What do you need to know to figure it out? I think I explained all above. In my case, I have just one activity and fragments. But I also want to know in other cases. – c-an Jun 21 '19 at 16:43
  • Just put your activity codes so i can do a testing and I’ll get back to you with an answer – Alireza Sharifi Jun 21 '19 at 17:30