且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

防止我的 Android 应用程序的多个实例由单个活动组成

更新时间:2023-11-22 16:17:46

像这样改变你的清单:

    <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>

包含 android:launchMode="singleTask" 并且不可能同时启动多个 Activity 实例.查看活动文档了解更多信息.

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.