How to stop android launching multiple instances?
Asked Answered
W

0

0

Following this thread,

Re-launch of Activity on Home button, but...only the first time

I'm able to launch multiple versions on my app when I launch it from a file browser, It does not happen from normal icon launch. I have set onCreate to do this.

@override
protected void  onCreate (final Bundle savedInstanceState)
{
    if (!isTaskRoot()) 
    {
        finish ();
        return;
    }
    super.onCreate (savedInstanceState);
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxx.xxx.xxx"
    xmlns:tools="http://schemas.android.com/tools"
    android:installLocation="auto">
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:glEsVersion="0x00020000" />

<application
        tools:replace="android:allowBackup"      
        android:label="@string/app_name"
        android:allowBackup="false"

android:icon="@mipmap/icon">


        <!-- Tell Cocos2dxActivity the name of our .so -->
        <meta-data android:name="android.app.lib_name"
                   android:value="MyGame" />

        <activity
            android:name="org.cocos2dx.cpp.AppActivity"

            android:clearTaskOnLaunch=  "true"

            android:screenOrientation   ="sensorLandscape"
            android:configChanges       ="orientation|keyboardHidden|screenSize"
            android:label               ="@string/app_name"
            android:theme               ="@android:style/Theme.NoTitleBar.Fullscreen"
            android:launchMode          ="singleInstance"
            android:taskAffinity        =""  >
            <intent-filter>
                <action android:name    ="android.intent.action.MAIN"                   />
                <category android:name  ="android.intent.category.LAUNCHER"             />
                <category android:name  ="android.intent.category.LEANBACK_LAUNCHER"    />
            </intent-filter>
        </activity>
        <meta-data
            android:name                ="io.fabric.ApiKey"
            android:value               ="XXXXXXX"
            />
    </application>
    <uses-permission android:name="android.permission.CAMERA"       />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.INTERNET"     />
</manifest>
Walston answered 28/4, 2019 at 7:59 Comment(3)
Did you try launchMode="singleInstance"?Tortuous
Please post your entire manifest. Also, how do you know that multiple instances of your Activity are created?Unto
Yes, I tried singleInstance. Edited with manifest. When I show android processes,there are multiple instances. This happens sometimes, not always.Walston

© 2022 - 2024 — McMap. All rights reserved.