File tree Expand file tree Collapse file tree
examples/demo/Assets/Scripts/Services Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -238,6 +238,23 @@ private void OnDestroy()
238238 _instance = null ;
239239 }
240240
241+ // After returnToApp() the test runner's first query can read a stale
242+ // accessibility snapshot: WDA on iOS (and to a lesser extent
243+ // UiAutomator2 on Android) caches the tree, and neither
244+ // BuildHierarchy's "structure changed" check nor the OS's own
245+ // notifications reliably invalidate that cache when the tree is
246+ // identical to before backgrounding. Rebuild and broadcast a
247+ // screen-changed notification unconditionally on every foreground so
248+ // the next XCUITest/UiAutomator2 query returns fresh data without the
249+ // Appium side having to spin on a fixed sleep.
250+ private void OnApplicationFocus ( bool hasFocus )
251+ {
252+ if ( ! hasFocus || _hierarchy == null || _root == null )
253+ return ;
254+ BuildHierarchy ( ) ;
255+ AssistiveSupport . notificationDispatcher ? . SendScreenChanged ( ) ;
256+ }
257+
241258 private void UnregisterTreeCallbacks ( )
242259 {
243260 if ( _root != null )
You can’t perform that action at this time.
0 commit comments