1

As the static shortcuts will always have FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TASK set, I've created TempActivity which is an invisible Activity i.e It'll start MainActivity and then calls finish(). And also as suggested in developer docs SecondActivity has android:taskAffinity="" in the app's AndroidManifest.xml file.

I have read Manage shortcuts and How to launch an existing instance of activity from static shortcut.

You can see Image A and Image B. There are different opinions.

Where should I add android:taskAffinity when I launch an existing instance of activity from the static shortcut in Android Studio? MainActivity or TempActivity?

Image A

enter image description here

Image B

enter image description here

S. Hesam
  • 5,266
  • 3
  • 37
  • 59
HelloCW
  • 843
  • 22
  • 125
  • 310

1 Answers1

1

It should be on TrampolineActivity of course. But the SO question you've provided has another error which makes it work eventually. If you read the docs carefully, you can see the second bullet saying

In the shortcuts resource file, the intent within the static shortcut should reference the trampoline activity

But the question from SO has wrongly set it on MainActivity's meta-data

Amin
  • 3,056
  • 4
  • 23
  • 34