There are two (mutually exclusive) kinds of unemployment benefits:
Alg: Calculated based on your previous salary and paid for up to two years (based on how long you worked and your age). If you quit voluntarily, the first three months nothing is paid out to you. They will (try to) offer you employment opportunities. This is an actual (mandatory) insurance and costs 3% of your income (up to a limit).
Alg II: Based on the bare minimum you need to live. Without any limits but you need to actively work on getting a job. This is financed through general taxes.
Alg is available to anyone (as everybody pays into the insurance). Foreigner might be required to leave the country at some point, depending on the kind of residence permit they hold.
Alg II is a bit more complicated: It is available to all persons that have their regular residence in Germany (with some restrictions). Again, foreigners may be required to leave the country based on the residence permit they have (and of course lose the benefit). For example, foreigners with a settlement permit (which is generally available after five years and allows unlimited residence) don't have any restrictions here.
Bullshit. It's very easy to get kicked out of the system, while one is still required to pay full contributions while employed in Germany. Let's say e.g. one works in Germany for years, moves to another EU country, ends up without a job within couple of months. German benefits are forfeit, that's about it regarding their social security. Money sunk in a black hole.
While the system is not perfect, in the scenario you describe times worked in another country can be recognised within the EU (by filling out form E 301).
What if one relocated to a country with very limited social support? Paying the highest (e.g. German) social contributions and getting the lowest (e.g. eastern European) social benefits. It's like getting spat in the face. Thanks.