Scripture says, If I regard iniquity in my heart, The Lord will not hear. Psalms 66:18 (NKJV).
I believe parents may understand this passage because persistent children may ask for something more than once (let's say he or she continues to ask for ice cream after being told no or wait until after dinner). After the given response the child continues to ask for ice cream but instead of saying no or later, the parent responds with silence. It's as if he or she doesn't hear the child. It's not that the parent can't hear the request he or she simply ignores the request.
Perhaps God is the same way, it's not that He can't hear our request, he just responds with silence until we do what He has told us to do. Peter instructed husbands to treat their wives properly so their prayers would not be hindered (1 Peter 3:7). He goes on to say if we want to love life and see good days we should avoid evil because the eyes of the Lord are on the righteous and his ears are open to their prayers. (1 Peter 3:10-12).
Although we may be involved in sin God can hear our prayers but He may not grant our requests. He does this out of love. He does this to encourage us to turn back to him and away from the darkness.
John Gill says, "the idea is, that in order that prayer may be heard, there must be a purpose to forsake all forms of sin." Remember sins means to miss the mark. We miss the mark of the commandment to love when we are in sin (whether it's loving God with all our heart or loving our neighbor).
Gill notes the principle in the following:
(a) to secret purposes of sin; to sinful desires, corrupt passions. and evil propensities;
(b) to acts of sin in individuals, as when a man is pursuing a business founded on fraud, dishonesty, oppression, and wrong;
(c) to public acts of sin, as when a people fast and pray Isaiah 58:1-14, and yet hold their fellow-men in bondage; or enact and maintain unjust and unrighteous laws; or uphold the acts of wicked rulers; or countenance and support by law that which is contrary to the law of God."
Remember sin doesn't have to maintain a hold on you because Jesus died to rescue you from Satan's power. (1 John 3:8, Acts 26:18, Colossians 1:13).
The choice is yours serve the God of life (John 17:2) and have your prayers answered or serve the god of death while enjoying the temporary pleasures of sin (John 10:10) and have God ignore your prayers.
I hope you will choose life and live. Choose life and have your prayers answered in the affirmative.