简体   繁体   English

意向过滤器仅工作一次

[英]Intent filter works only once

I have an activity called "MainActivity", this is my main activity which declared in the manifest file as launcher: 我有一个名为“ MainActivity”的活动,这是我在清单文件中声明为启动器的主要活动:

<activity
        android:name="com.example.tester.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VOICE_COMMAND" />

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

The VOICE_COMMAND works only one time and then nothing is happen. VOICE_COMMAND只工作一次,然后什么也没有发生。 I have tried to separate it into 2 activities: 1 activity is the main and the other is associated with the VOICE_COMMAND intent filter, and still, the application works only once. 我尝试将其分为2个活动:1个活动是主要活动,另一个活动与VOICE_COMMAND意向过滤器相关联,但该应用程序仅能运行一次。 If it's separated into 2 activities it works fine only when the application starts immediately from the launcher, but if the application starts from the second activity (with the VOICE_COMMAND intent filter) it works only once. 如果将其分为两个活动,则仅当应用程序立即从启动器启动时,它才能正常工作;但是,如果应用程序从第二个活动(使用VOICE_COMMAND意向过滤器)启动,则它只能工作一次。 Any suggestion? 有什么建议吗? Thank you 谢谢

I have found the answer: Setting the attribute: 我找到了答案:设置属性:

android:launchMode="singleTask"

and it works fine. 而且效果很好。 Thank you 谢谢

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

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