Unity-Technologies / uaal-example

Other
736 stars 234 forks source link

Unload, Activities stack and Back button #39

Open ctriantaf opened 3 years ago

ctriantaf commented 3 years ago

Hello everyone,

We have a use case where we need to execute Unity in the same process as the main app. So instead of killing the activity (and thus killing the process) we are unloading the UnityPlayer. However, by unloading the MainUnityActivity remains in the activities stack and the back button behaviour is broken as follows:

Let's say that our stack is as follows: A > B > C > MainUnityActivity. By unloading and going back to C our stack becomes A > B > MainUnityActivity > C. So when we click the back button MainUnityActivity is brought to the front of the stack again.

The UaaL solves this by overriding onBackPressed and explicity going to the previous activity each time. When it ends up in the "root" activity it calls finishAffinity which closes all remaining activities, including MainUnityActivity. Our module will be integrated into apps with different structure that we can't control so we can't use the above workaround.

Is there a way to unload or kill the Unity Player and not alter the back button functionality? We created an example project based on the UaaL example which shows the issue we are facing (see below). There are // NOTE: in a few places that provide information about the back button flow. The activity stack in the example is as follows: RootActivity > MainActivity > MainUnityActivity.

What we would like to achieve is to go back to RootActivity by only using the back button and without specifying any activities - like in the UaaL example.

Example project here.

Thank you, Christos

futouyiba commented 2 years ago

Interested in this!

Shivamdhuria commented 10 months ago

hey @ctriantaf , did you find a workaround for this?