Get XPath from MobileElement

I want to get the Xpath of a MobileElement, and I don’t know how to get it.

I know the option exists in the Inspector, but I need it programmatically.

My usecase:
I’m locating/indentify several elements on a app. After identifying all elements and I’m certain I can handle this setting/buttons I start interacting. however, during interaction, my stored MobileElements might change. So I would need to identify elements again. Then the findElementsByID method comes handy since the ID likely stays the same. However, some elements don’t provide a ResourceID thus, it might be useful to have the xpath of the element to use the findElementByXpath.