简体   繁体   English

从NFC启动的活动/应用程序永远不会出现在最近的应用程序列表中

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

I am developing an application targeted at ICS+ phones. 我正在开发针对ICS +手机的应用程序。

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. 在该应用程序中,我有一个启动画面,以及可以从启动画面或通过NFC触摸启动的几个其他画面。 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. 如果在ThingActivity之前打开了启动屏幕,即使在按下“主页”按钮时不是首个活动,启动屏幕也会显示在“最近使用的应用程序”列表中。 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. 尽管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. 怪异的行为是,此行为也适用于从包含NFC意向过滤器的活动启动的任何活动,或从这些活动启动的任何活动,等等。

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. 如果我删除了意图过滤器,此行为将消失,并且最上面的任何活动都会始终显示在“最近使用的应用程序”列表中,但会被破坏,因为NFC是一项核心功能。

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. Android如何处理活动和任务可能非常棘手。 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. 一项可能至关重要的信息是,通过NFC意图启动您的活动时,它将作为单独的任务启动。 I suspect that that has to do with the behaviour you are observing. 我怀疑这与您观察到的行为有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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