Android App name is not displayed in the multitask

2019-09-04 15:21发布

I've developed a simple NFC application that reads and displays the data(NDEF Records) present in the NFC tag. I modified the Manifest file so that whenever a tag gets tapped, my app gets opened.

Now the problem is when I manually open the app and check the multitasking screen, it displays my app name i.e NFCReader but when the app gets opened itself when a tag comes in contact with the device, my app gets opened but when I check the multitasking screen, it doesn't display my app name. Instead it displays NFC Service. What should I do to overcome this issue?

1条回答
神经病院院长
2楼-- · 2019-09-04 16:14

I assume that you have set your activity declaration, in your manifest, to something like this:

<activity
     android:name=".packagename.MainActivity"
     android:alwaysRetainTaskState="true"
     android:launchMode="singleTask"
     android:theme="@style/AppTheme.Main">
     <intent-filter>
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.LAUNCHER" />
     </intent-filter>
     <intent-filter>
         <action android:name="android.nfc.action.NDEF_DISCOVERED" />
         <category android:name="android.intent.category.DEFAULT" />
         <data
             android:host="domain.com"
             android:scheme="http" />
     </intent-filter>
</activity>

I think the answer to your question is the following line of code that you forgot to add: android:launchMode="singleTask"

I invite you to read about launch modes here and here.

Please note: This answer is based on the use of Reader mode API, otherwise check this answer.

Hope this helps!

查看更多
登录 后发表回答