der Einfall
idea
A sudden thought or spontaneous idea that comes to someone's mind.
Mir kam gerade ein genialer Einfall, wie wir das Problem lösen können.
I just had a brilliant idea for how we can solve the problem.

idea / invasion / incidence
Loading your saved state.
idea
A sudden thought or spontaneous idea that comes to someone's mind.
Mir kam gerade ein genialer Einfall, wie wir das Problem lösen können.
I just had a brilliant idea for how we can solve the problem.

'Der Einfall' (idea/invasion/incidence/collapse) is the noun form of the separable verb 'einfallen'. The different meanings of the noun correspond directly to the meanings of the verb: an idea occurs to someone, troops invade a country, or a building collapses.
Plötzlich fiel ihr die Lösung für das Rätsel ein.
Suddenly the solution to the puzzle occurred to her.
You can recognize the meaning from the context: With creativity and problems, it is about an idea. With military and history, it is about an invasion. With physics and optics, it is about rays striking a surface. With mining and buildings, it is about a collapse.
Der plötzliche Einfall von Kaltluft führte zu einem Wetterumschwung.
The sudden influx of cold air led to a change in the weather.
When a person has an idea, the phrase 'einen Einfall haben' (to have an idea) is often used. The related verb 'einfallen' needs the dative: 'Mir fällt etwas ein.' (Something occurs to me.) Not: 'Ich falle etwas ein.'
Ich hatte gestern den besten Einfall für dein Geburtstagsgeschenk.
Yesterday I had the best idea for your birthday present.
The most common meaning, 'Idee' (idea), is often combined with adjectives like 'gut' (good), 'genial' (brilliant), 'plötzlich' (sudden), or 'lustig' (funny). A fixed phrase is 'einen Einfall haben' (to have an idea).
Das war wirklich ein lustiger Einfall von dir, eine Kostümparty zu machen.
That was really a funny idea of yours, having a costume party.
The meaning 'Invasion' (invasion) is limited to military or historical contexts. It describes the hostile entry of armed groups into a territory.
Das Museum dokumentiert den Einfall der Truppen im Jahr 1944.
The museum documents the invasion of the troops in 1944.
This meaning is a technical term from physics, specifically optics. It is used almost exclusively in scientific or school texts to describe rays striking a surface.
Im Physikunterricht haben wir den Einfall von Licht auf eine Linse untersucht.
In physics class, we investigated the incidence of light on a lens.
idea
'die Idee' and 'der Einfall' both mean a thought that can lead to a solution or a plan. 'die Idee' is more general and can be spontaneous, but also thought through or developed over a longer time. 'der Einfall' emphasizes more strongly that the thought comes suddenly. Learners may confuse the words because an 'Einfall' is often a kind of 'Idee'. If you are speaking neutrally about a thought or plan, 'Idee' almost always fits. If you want to say that something suddenly comes to mind, 'Einfall' is more precise.

Beim Kochen hat Maria plötzlich einen Einfall für ein neues Rezept.
While cooking, Maria suddenly had an idea for a new recipe.
Ich habe eine Idee für das Wochenende.
I have an idea for the weekend.