我的Andr​​oid应用程序的一个活动,由prevent多个实例 [英] Prevent multiple instances of my Android application composed of a single activity

查看:123
本文介绍了我的Andr​​oid应用程序的一个活动,由prevent多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从一个单一的活动组成的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.

这篇关于我的Andr​​oid应用程序的一个活动,由prevent多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆