Search code examples
androidaccessibilityserviceaccessibility

getRootInActiveWindow() returns null


I would simplify my issue by this scenario. I have 2 buttons B1 and B2 in a third party app in which I'm testing accessibility.

Initially I'm able to get both the elements by their id using getRootInActiveWindow().findAccessibilityNodeInfosByViewId(BUTTON_ID). But when I'm performing click on B1, a fragment windows is opened. Now after closing the fragment, getRootInActiveWindow() is returning null and I'm not able to find that element anymore.

Maybe this is happening because getRootInActiveWindow() would be switching to the fragment window when it's opened, and when it is closed it is becoming null. So I just need any workaround to get the actual parent root node so that I can find the elements or any other alternative which would help in finding that element or maybe just refresh the view anyhow so that getRootInActiveWindow() would again point to the root parent window.


Solution

  • Using getWindows and searching for your button in app windows is probably more robust that getRootInActiveWindow.