How do we get a Male body or Female body or become a devotee of Krishna or escape this material world ?

 Purport :

 “Whatever state of being one remembers when he quits his body, that state he will attain without fail.” The atmosphere of the subtle body at the time of death is created by the activities of the gross body. Thus the gross body acts during one’s lifetime, and the subtle body acts at the time of death. The subtle body, which is called liṅga, the body of desire, is the background for the development of a particular type of gross body, which is either like that of one’s mother or like that of one’s father. According to the Ṛg Veda, if at the time of sex the secretions of the mother are more profuse than those of the father, the child will receive a female body, and if the secretions of the father are more profuse than those of the mother, the child will receive a male body.

These are the subtle laws of nature, which act according to the desire of the living entity. If a human being is taught to change his subtle body by developing a consciousness of Kṛṣṇa, at the time of death the subtle body will create a gross body in which he will be a devotee of Kṛṣṇa, or if he is still more perfect, he will not take another material body but will immediately get a spiritual body and thus return home, back to Godhead. This is the process of the transmigration of the soul. Therefore instead of trying to unite human society through pacts for sense gratification that can never be achieved, it is clearly desirable to teach people how to become Kṛṣṇa conscious and return home, back to Godhead. This is true now and, indeed, at any time. Srimad Bhagavatham 6.1.54