0

I am facing an issue in android application that Multiple instances of App are seeing in recent list.

<application
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.CEC"
    tools:replace="android:theme,android:allowBackup,android:usesCleartextTraffic"
    android:usesCleartextTraffic="false"
    android:taskAffinity=""
    tools:ignore="UnusedAttribute">

    <activity
        android:name=".ui.main.MainActivity"
        android:configChanges="uiMode"
        android:launchMode="singleTop"
        android:taskAffinity="${applicationId}.MainActivity"
        android:screenOrientation="portrait" />

    <activity
        android:name=".ui.splash.activities.SplashActivity"
        android:exported="true"
        android:screenOrientation="portrait"
        tools:ignore="LockedOrientationActivity"
        tools:replace="android:exported">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

I am calling my method for recreating current activity for apply locale changes.

fun recreateActivity() {
    val intent = getIntent()
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
    intent.putExtra("activity_locale_changed",true)
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
    finish()
    startActivity(intent)
}

After implementing this code sometimes App is working fine or sometime app is creating multiple instances inside recent app list.

I have checked Multiple instances of app in recent app list of tablet(android), Multiple Instances of the same app are generated in stack, multiple instance of same app in android

Laxmi Kant
  • 71
  • 3
  • It's making android:launchMode="singleTop" android:taskAffinity="${applicationId}.MainActivity. Why you added these lines – Gobu CSG Jul 05 '22 at 20:02
  • 1
    My Android application is vulnerable to a recently discovered android vulnerability called strandhogg (task hijacking). This allows a malicious app to Hijack target application UI leading to showing false information to the victim such as a fake login page to steal user credentials. I want to prevent this vulnerability from the app. So I took a step for remove this issue I used android:taskAffinity="${applicationId}.MainActivity". Please let me know what can I do for resolving this issue?? – Laxmi Kant Jul 06 '22 at 08:45
  • I hope this useful https://stackoverflow.com/questions/17872989/android-task-affinity-explanation – Gobu CSG Jul 06 '22 at 09:27
  • Why are you setting the taskAffinity to an empty string in the `` declaration? – David Wasser Jul 07 '22 at 15:58
  • @DavidWasser What should I be use?? – Laxmi Kant Jul 07 '22 at 16:36
  • The default taskAffinity is the package name. You should remove that and use the default. – David Wasser Jul 07 '22 at 21:39
  • I don't understand how setting taskAffinity to "{applicationId}.MainActivity" will help solve the strandhogg issue. If the attacker knows this he can use this instead of your package name to hijack the task. Also, please explain how `MainActivity` is launched from `SplashActivity`. Also, if you can provoke the "multiple tasks in recents" issue, please use `adb shell dumpsys activity activities` to dump the task list and post the relevant parts of that (all the tasks that contain your app's activities) in your question. – David Wasser Jul 07 '22 at 21:54
  • @DavidWasser Firstly I did not use taskAffinity for the MainActivity. When the issue arise then I used android:taskAffinity="${applicationId}.MainActivity". In both cases application is creating double instances in the recent app list. – Laxmi Kant Jul 08 '22 at 04:54
  • Please use the `adb shell dumpsys` command to get more info and edit your question and add that info there. Otherwise we can't help you. – David Wasser Jul 08 '22 at 10:46

0 Answers0