What Makes A Singletask Activity Have 2 Instances?
As per the docs, singleTask activities can't have multiple instances. The only activity of my app is singleTask, and it has 2 instances at the same time. Steps to recreate the issu
Solution 1:
An Android application can have multiple tasks. Each task can have multiple activities. singleTask
and singleInstance
control the behaviour of the activity (its uniqueness) inside the task, but it can happen that an App has two or more tasks with the same Activity
inside.
This is what is actually seen here, an App with two tasks with an LauncherActivity
inside, one for each tasks. As workaround, ensure that there is always one task in the app. On the LauncherActivity
onCreate
add:
val appTasks = getSystemService(ActivityManager::class.java).appTasks
if (appTasks.size >= 2) {
appTasks.dropLast(1).forEach { it.finishAndRemoveTask() }
appTasks.last().moveToFront()
return
}
Post a Comment for "What Makes A Singletask Activity Have 2 Instances?"