Allah created the universe and is all knowing! So He knows who is going to obey Him or not and is going to hell or Heaven. So if you have led a good life and something happens in your life that make you turn into a bad person, I believe, Allah has foreseen this and He also knows if your will repent or not because He is all knowing! In other words it s already preordained who is going to hell or Heaven, is n t it?
Your question bring us to a very deep discussion. Is a human obligate for his acts or he has a full freedom to do whatever he wants.
Imam Sadeq(as) answers this with his say:
The example in @Battle-of-Karbala is great explanation of this say.
ِAnother example.. you are an electric train driver. Of course if electricity is off then the train will stop, but you as a driver has the ability to stop, increase ,or decrease your speed. This is the same relation between us and ALLAH.
As ALLAH knows everything and knows who will go to heaven and who will go to hell, ALLAH gives us the ability to choose among right and false actions, and everyone has the ability to change his destiny when one's change his action.
I only give you an example, which I heard from an Islamic idealist/thinker. I hope then you can understand what it means.
A teacher teaches his pupils. He knows who are attentive in the classes and who are not. Again from his experience he knows that inattentive students cannot pass in the exam.
One day he made a speech saying who will pass the exam and who will not.
After the exam, everyone saw that teacher’s predictions become true.
So failed students thought that this is the teacher who is responsible for their failure.
But you know the teacher is not responsible at all. It is the result of inattentiveness of those students.
Allah is the wisest and most experienced – there is no limitation. So why not he know everything about us?
Mohammad salla Allah 3alayh wa salam usually uses analogies so that people can understand the "Big Picture". I'm going to use his way, so think of it this way:
You already watched a movie and you know what will happen.
You've then invited your friend to watch that same movie again.
The situation is as follows:
So as you've seen, it's like you already know everything without affecting the character influence.
Hope this helps!
Wa3alykomo assalam. Allah bless you and forgive you inshaAllah (God willing).
I have answered this before:
Yes, Allah knows everything and has the knowledge of future (even the farthest of the time).
When we make a mistake, Allah knew! When we go bad Allah knew, when we will die, Allah knows!
Allah never sent us down to find out what would happen, and who would go to Hell or Heaven. He knew it always, he just sent us down to give us a chance to change our destiny. You might have a belief that prayers change destiny. Allah forgives his people if they ask for forgiveness.
Otherwise, yes, Allah knows everything.