I had a Unity project,then I built it into a Android apk.
There is some code can launch a new Activity.
By default, SceneA is shown.
Then,I switch to Home Screen,then switch back.
The SceneA is shown, but BActivity is disappered.
I want keep BActivity shown.
Any sugesstion?
when I switch back to App from Home Screen, My custom activity BAcitivity is destoried.
It called onDestroy
but not called onResume
.
There is some different between Pure Android
and Unity Android
.
Pure Android
launch KeepActivity
KeepActivity onCreate
KeepActivity onStart
KeepActivity onResume
handleWindowFocusChanged mWindowFocusChanged true mUpcomingWindowFocus true mAdded true
switch to Home Screen
handleWindowFocusChanged mWindowFocusChanged true mUpcomingWindowFocus false mAdded true
KeepActivity onPause
setWindowStopped stopped:true
KeepActivity onStop
switch back to App
KeepActivity onRestart
KeepActivity onStart
KeepActivity onResume
handleWindowFocusChanged mWindowFocusChanged true mUpcomingWindowFocus true mAdded true
Unity Android
launch KeepActivity
KeepActivity onCreate UnityPlayer.currentActivity:com.unity3d.player.UnityPlayerActivity@468f2d3
KeepActivity onResume
handleWindowFocusChanged mWindowFocusChanged true mUpcomingWindowFocus true mAdded true
switch to Home Screen
handleWindowFocusChanged mWindowFocusChanged true mUpcomingWindowFocus false mAdded true
KeepActivity onPause
switch back to App
KeepActivity onDestroy
The reason is UnityPlayerActivity
has android:launchMode="singleTask"
.(It happens not matter Unity and Android.)
just remove it, the problem can be resolved.
But I don't know if there will be other problems.
See:
https://forum.unity.com/threads/android-launchmode-why-does-unity-have-it-as-singletask.992683/
Setting android:launchmode for UnityPlayerActivity
App restarts rather than resumes
The reason is UnityPlayerActivity
has android:launchMode="singleTask"
.(It happens not matter Unity and Android.)
just remove it, the problem can be resolved.
But I don't know if there will be other problems.