The characteristics flame test color of metal ions are because of the atomic emission spectra.
When an atom absorbs a particular wavelength radiation, the electrons within it, move from lower energy level to the higher level of energy. Such a procedure is called absorption. When this stimulated electron to come back to its ground state, it loses energy in particular color on the basis of the frequency of the absorbed radiation. Such a procedure is called emission.
As an atom exhibit, distinct levels of energy, the level close to the nucleus possess less energy in comparison to the level, which is far from the nucleus. So, electrons move from lower energy level to the higher level by attaining particular energy, and after excitation, it comes back from high energy level to a low energy level with the emission of light.
According to Planck's concept, there is a specific difference of energy between the two energy level, so such energy difference is quantized. Only those radiation are absorbed, which are equivalent to the difference of energy between the two levels.