简体   繁体   中英

Activity/Application Launched From NFC Never Appears in Recent Apps List

I am developing an application targeted at ICS+ phones.

In the application, I have a Splash screen, and a couple other screens that can be launched from the Splash screen or via NFC touch. One of my activities contains the following intent filter:

        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />

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

            <data android:mimeType="application/com.myapp.thing.android.beam.ip" />
        </intent-filter>

For some reason I can't figure out, any time the activity containing the above intent filter is launched, the activity does not appear in the "Recent Apps" list when the user pushes the "Home" button. Via the debugger I have verified that it is not being destroyed, just stopped.

If the Splash screen was open prior to the ThingActivity, the Splash will show in the Recent Apps list, even if it was not the top activity when the Home button is pushed. Clicking the Splash in the Recent Apps list will show the Splash, not the activity that was previously on top. Any activity on top of the Splash screen seems to be 'lost' despite still running threads and receivers in the bg.

The weirder behavior is that this behavior also applies to any activity launched from the activity containing the NFC intent filter, or any activity launched from those activities, etc.

If I remove the intent filter, this behavior disappears and whatever activity was on top will ALWAYS show in the Recent Apps list but becomes broken, because NFC is a core feature.

My full Manifest is as follows:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.myapp.thing"
    android:versionCode="1"
    android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="16" />
<!-- Permission required to use the TCP transport -->
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" >
</uses-permission>
<!-- Permission required to use the Bluetooth transport -->
<uses-permission android:name="android.permission.BLUETOOTH" >
</uses-permission>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" >
</uses-permission>
<uses-permission android:name="android.permission.BROADCAST_STICKY" >
</uses-permission>
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >
</uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK" />

<!-- RECORD_AUDIO is needed to create an audio recorder -->
<uses-permission android:name="android.permission.RECORD_AUDIO" >
</uses-permission>

<!-- MODIFY_AUDIO_SETTINGS is needed to use audio effects such as environmental reverb -->
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" >
</uses-permission>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".ui.SplashActivity"
        android:configChanges="keyboardHidden|orientation"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.myapp.thing.ui.ReceiverActivity"
        android:configChanges="keyboardHidden|orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name="com.myapp.thing.ui.BaseActivity"
        android:configChanges="keyboardHidden|orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name="com.myapp.thing.ui.BroadcasterActivity"
        android:configChanges="keyboardHidden|orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name="com.myapp.thing.ui.ChooseFileActivity"
        android:configChanges="keyboardHidden|orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name="com.myapp.thing.ui.ThingActivity"
        android:configChanges="keyboardHidden|orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />

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

            <data android:mimeType="application/com.myapp.thing.android.beam.ip" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEND_MULTIPLE" />
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="audio/*" />
        </intent-filter>
    </activity>

    <service
        android:name="com.myapp.thing.service.ThingService"
        android:label="ThingService" >
    </service>
</application>

Why does including this intent filter prevent my Application from being in the recent apps list?

I do not understand all the described behaviour, I must admit. How Android handles activities and tasks can be quite tricky. One piece of perhaps crucial information is that when your Activity is launched through an NFC intent it will be launched as a separate task. I suspect that that has to do with the behaviour you are observing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM