The relationship is always mutual. Our relationship with God is sometimes severed and cut off or tend to become weak; but He is always and everywhere with us. God, the Exalted say, "And He is with you wheresoever ye may be. And Allah sees well all that ye do."[1] Hence, if our connection with God becomes weak, we must look for the cause or setback. It has been said that the best way to get friendly with someone is to be more often in touch with him. Psychologically, this point has been considered to be undeniable and without a shred of doubt.
We must try to find what has created a distance between us and God. Sometimes, arrogance, haughtiness, jealousy, feeling of needlessness and other sins which originate in the mind create a distance between us and God. That is to say, the thinking power has been paralyzed in the sense that it cherishes only bad thoughts. Sometimes, some sins are committed by organs and limbs causing an obstruction (barrier) between us and God.
As you have stated in your message, it is likely that your getting away from God may originate in those thoughts. Since, there is a thought behind every action, or in other words, there is an action beyond knowledge, we should control the mind and let not everything enter it. Although such an action seems to be difficult, the results are very positive.
Sometimes, the thoughts that enter the mind come from the Shaitan which should be warded off and repelled immediately because they force man into action. God, the Exalted, says, "And most surely the Shaitans suggest to their friends that they should contend with you.[2]" Therefore, one should prevent satanic thoughts from entering his mind.
One of the biggest and most important factors that leads man away from God and causes him to become negligent are the unwanted memories."[3]
Some of these ungodly memories have so much influence on the individual that he loses his concentration amid performing the best act of worship i.e. prayer. It is therefore necessary to prevent the growth and development of such memories. The memories develop gradually as a result of talking and speaking with someone, listening, being in some gatherings, reading some magazines etc. And when they get profuse and accumulated, they create some sort of enthusiasm. Finally, they become part of a man's secondary habit coming easily to his mind and causing him to be oblivious of God. For this reason, those who have a materialistic mindset are constantly seeking worldly pleasures.[4]
What was said was an analysis of the problem but we should see what the solution to the problem is.
As was said earlier, it is necessary to prevent such thoughts from entering the mind and one should endeavor to ward off those thoughts that are coming to his mind. The Quran gives a solution; (one should guard himself against evil things and remember God. He should be careful as to where he goes, what he reads, listens, eats and wears. When he takes care of all these, gradually, zikr (remembrance) of God will be instilled in his heart and thereupon, good memories will be formed in his mind. For this reason, the Quran suggests “remembering God” as a way for coming out of negligence and for seeking proximity to the Truth.)[5]
God, the Exalted, says: “O you who believe! Remember Allah with much
remembrance.”[6] When remembrance increases in one’s heart, he starts to get interested in Him and this interest becomes his secondary habit so much that he remembers God in all sitautions.
Having said that, one should, therefore, pave the way for purifying and cleansing his heart and mind from bad memories and from impurities by remembering God and preventing the evil influences of negative and tormenting thoughts.
May Allah grant you success.