Detecting Application Close/Minimize (Crown Button)

Hey,

is there a way to detect when the application is closed/minimized when pressing the crown in an unbounded application. We have 2 scenes, one bounded volume and one unbounded and we would like to switch from unbounded to bounded when the application was closed/minimized (whatever the crown button does).

Okay it seems this works for us.

var volumeCamera = FindObjectOfType<VolumeCamera>();
  
volumeCamera.OnWindowClosed.AddListener(GoBack);
volumeCamera.OnWindowFocused.AddListener(OnWindowFocus);

But I have another problem now. When going from bounded to unbounded the first time around everything works fine but the second time, there is no proper tracking. It seems like the AR Session is not happy being destroyed. Any idea?

This is the error we get from XCode:

InvalidOperationException: Trying to access unloaded resource! [b92519f0-d7c2-443f-9ef5-8377ce05038b (has 3 polyspatial refs, is not unity referenced): resource alive: False iid=11466 name=Square type=Texture2D
  at Unity.PolySpatial.Internals.AssetRepresentation.get_Resource () [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.PolySpatial.Internals.LocalAssetManager.GetRegisteredResource (Unity.PolySpatial.Internals.PolySpatialAssetID assetID) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.PolySpatial.Internals.LocalAssetManager.GetRegisteredResource[T] (Unity.PolySpatial.Internals.PolySpatialAssetID assetID) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.PolySpatial.Internals.SpriteRendererTracker.UpdateSpriteInfoIfNeeded (Unity.PolySpatial.Internals.PolySpatialInstanceID iid, UnityEngine.SpriteRenderer source, Unity.PolySpatial.Internals.PolySpatialSpriteRendererTrackingData* destination) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.PolySpatial.Internals.SpriteRendererTracker.TransferObjectData (UnityEngine.SpriteRenderer source, Unity.PolySpatial.Internals.TrackingData`1[Unity.PolySpatial.Internals.PolySpatialSpriteRendererTrackingData]* trackingData, Unity.PolySpatial.Internals.IChangeListWritable`1[TEngineData] engineData) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.PolySpatial.Internals.UnityObjectTracker`3[TObject,TEngineData,TTrackingData].TransferObjectAndUpdateTrackingData (UnityEngine.Object o, TTrackingData* data) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.PolySpatial.Internals.SpriteRendererTracker.TrackNewAndModifiedObjects (UnityEngine.Object[] changedObjects) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.PolySpatial.Internals.ObjectDispatcherProxy.<.ctor>b__12_0 (UnityEngine.TypeDispatchData real) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.ObjectDispatcher+<>c.<.cctor>b__54_0 (UnityEngine.Object[] changed, System.IntPtr changedID, System.IntPtr destroyedID, System.Int32 changedCount, System.Int32 destroyedCount, System.Action`1[T] callback) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.PolySpatial.Internals.ObjectDispatcherProxy.DispatchTypeChangesAndClear (System.Type type, System.Action`1[T] fetchProxyTypeCallback) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.PolySpatial.Internals.UnityObjectTracker`3[TObject,TEngineData,TTrackingData].TrackObjectChanges (UnityEngine.LayerMask cullingMask) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.PolySpatial.Internals.PolySpatialUnityTracker.TrackObjectChanges (UnityEngine.LayerMask cullingMask) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.PolySpatial.Internals.PolySpatialUnitySimulation.Update () [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.PolySpatial.Internals.PolySpatialCore.PolySpatialAfterLateUpdate () [0x00000] in <00000000000000000000000000000000>:0 
Unity.PolySpatial.Internals.ObjectDispatcherProxy:DispatchTypeChangesAndClear(Type, Action`1)
Unity.PolySpatial.Internals.UnityObjectTracker`3:TrackObjectChanges(LayerMask)
Unity.PolySpatial.Internals.PolySpatialUnityTracker:TrackObjectChanges(LayerMask)
Unity.PolySpatial.Internals.PolySpatialUnitySimulation:Update()
Unity.PolySpatial.Internals.PolySpatialCore:PolySpatialAfterLateUpdate()

I post this here if anybody stumbles upon the same issue. For us it was more related to AR Foundation. This solution worked for us:

Using the SceneUtility.cs & SceneUtilitySetup.cs from the AR Foundation samples