我的Andr​​oid应用程序的一个活动,由prevent多个实例我的、多个、应用程序、实例

由网友(天然淡雅香)分享简介:我是从一个单一的活动组成的Andr​​oid应用程序。我怎样才能确保我的应用程序只有一个实例(== 活动)将存在于一个给定的时间?我有一个情况,就是我成功通过点击应用程序图标多次(这不会重现所有的时间),打开我的应用程序的多个实例。I have an Android application which is co...

我是从一个单一的活动组成的Andr​​oid应用程序。 我怎样才能确保我的应用程序只有一个实例(== 活动)将存在于一个给定的时间? 我有一个情况,就是我成功通过点击应用程序图标多次(这不会重现所有的时间),打开我的应用程序的多个实例。

I have an Android application which is composed from a single Activity. How can I assure that only one instance of my application (== Activity) will exist in a given time? I got to a situation in which I succeeded to open multiple instances of my app by clicking on the app icon multiple times (this doesn't reproduce all the time).

推荐答案

改变你的表现是这样的:

change your manifest like this:

    <activity
        android:name="com.yourpackage.YourActivity"
        android:label="@string/app_name"
        android:launchMode="singleTask" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

包括安卓launchMode =singleTask,这将是不可能让你的活动在同一时间推出的多个实例。 查看活动文档为多。

include the android:launchMode="singleTask" and it will not be possible to have multiple instances of your Activity launched at the same time. See the activity docs for more.

阅读全文

相关推荐

最新文章