Search code examples
androidunity-game-enginemobileandroid-activity

My Activity disappeared after recenter via launch icon


Prerequisites

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.

Question

Then,I switch to Home Screen,then switch back.

The SceneA is shown, but BActivity is disappered.

I want keep BActivity shown.

Any sugesstion?

Replenish 1:

when I switch back to App from Home Screen, My custom activity BAcitivity is destoried.

It called onDestroy but not called onResume.

Replenish 2:

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

Solution

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.


Solution

  • 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

    Solution

    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.