Is there a way to prevent getting endometriosis?

No. Since we don't really understand how women get endometriosis we surely don't have a way to prevent it.
Lifestyle.... My questions is always: why? Endometriosis is considered to be due to disrupted hormone levels. The possible causes for hormone disruption are toxins, nutritional reasons, and neurotransmitter imbalances (see neuroresearch. Com for this one). Therefore, to prevent endometriosis, work on correcting these issues. Specifics are best discussed with a doctor familiar with these approaches.