How do I know when to use back or close button (or both) on mobile apps

I want to know when and why should I use the X or back button on top of the page. And additionally, related to that, how should I judge the transitions, when should a page just slide from the right, or slide up, etc. How should I make those decisions based on rational proven UX heuristics or testing?

I just can't find it anywhere and when I try to benchmark it just feels like there is not much of a pattern between different apps.

Thank you in advance!

Example images below

example of back usage

example of X usage