Search code examples
androidmultithreadingandroid-intentandroid-activitylaunchmode

Activity with singleInstance launchMode and a new Thread


I'm a bit confused really. When it says that

Activities with singleInstance launchmode uses the singleton pattern, and that instance will be the root activity of a new task

When it says new task, does it mean that the launching activity will get executed in a new thread??? Or the android system just uses flags to control activities navigation internally with datastructures within the Main Thread


Solution

  • Activities with singleInstance launchmode uses the singleton pattern

    This is misleading. Activities, whatever the launchmode, should never be considered singletons. True, there is only one instance of the Activity when using singleInstance, but the normal Activity lifecycle still occurs and it is not safe to keep a static reference to any Activity.

    When it says new task, does it mean that the launching activity will get executed in a new thread???

    No, all Activities live in the main thread and you should only interact with them there. The confusion comes from the usage of the word task, which does not refer to threading in this case. It refers to a group of Activities. There's a useful reference concerning this subject in the official docs.