4

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?

user1120134
  • 251
  • 2
  • 5
  • Are you calling `finish()` from that Activity? – twaddington Mar 14 '13 at 20:12
  • No, it is not finished unless the user explicitly hits a button. I have debugged it, onDestroy is not hit. – user1120134 Mar 14 '13 at 20:21
  • On the device you are testing, have you by chance enabled the developer option "don't keep activities"? – David Wasser Mar 14 '13 at 21:15
  • Regarding returning to the app after pressing HOME and returning to the splash screen instead of the activity that was on top of the stack, this is probably the nasty Android launcher bug. Make sure that you launch your application for the first time from the list of available applications, **not from the installer or from an IDE like Eclipse or IntelliJ**, see http://code.google.com/p/android/issues/detail?id=2373 and http://code.google.com/p/android/issues/detail?id=26658 – David Wasser Mar 14 '13 at 21:20
  • @DavidWasser I do NOT have the "Don't Keep Activities" option enabled. – user1120134 Mar 14 '13 at 21:35
  • @DavidWasser I am not launching from Eclipse, I am launching from the programs list. It behaves the same way whether I do it from Eclipse or if I install directly from APK and launch from programs list. Whenever the ThingActivity is launched via NFC, it is not shown in the apps list after hitting 'home' If it is launched programmatically from the Splash activity, it is shown in the recent applications list after hitting 'home'. – user1120134 Mar 14 '13 at 21:42

1 Answers1

2

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.

NFC guy
  • 10,151
  • 3
  • 27
  • 58
  • It is indeed something to do with this. If I make my activity with launchMode singleTask, things work a bit better and the activity is in the recent applications list. – user1120134 Mar 15 '13 at 17:05