Reputation: 10108
I'm building an Android game on Unity which has a button that opens a new activity.
The problem is when building the APK, no matter what I put in my custom AndroidManifest.xml, Unity overrides it and sets android:launchMode for com.unity3d.player.UnityPlayerActivity
to singleTask
.
This results in the following scenario: Open the game, tap the button that opens the activity, tap the home button to go to background, relaunch the app using the icon - the new activity is destroyed and instead I see the same main UnityPlayerActivity (it's the same original one - nothing has been recreated).
In order to fix it - I had to create the apk, decompile it using apktool, hardcode android:launchMode=0
for com.unity3d.player.UnityPlayerActivity
(which means standard
instead of singleTask
), recompile it, resign it, and only then install it.
This is obviously a total hack and can't be used as an actual solution. I need to find a way to set the android:launchMode
myself.
How can I do that?
Upvotes: 4
Views: 1549
Reputation: 10108
After investigating the issue, I found that the reason for this behaviour is that Unity is setting the launchMode on the AndroidManifest.xml for the UnityPlayerActivity to be singleTask.
When the app launches a new activity, which is – in the instance of launchMode:singleTask – closed in case of a relaunch.
No matter what we set in our custom AndroidManifest.xml, Unity will just override it to be singleTask and according to the official Unity Documentation – Unity only supports launchMode:singleTask.
Upvotes: 1