To minimize the risk of fire, recessed lights have a thermal protector that shuts them off when they get too hot. Be sure the bulb doesn’t exceed the maximum wattage indicated inside the metal housing.
And check whether a reflector-type bulb is required. If the bulb is the proper size and type, loosen the wing nuts or screws that adjust the bulb-holder’s position inside the metal housing, slide the bulb unit down a little, and then re-tighten.
If possible, be sure insulation inside the ceiling is held back away from the fixture at least 3 inches. A flicker or spark indicates faulty wiring or a defective switch.
If you’re competent at handling electrical problems, shut off the power to the circuit and check the wire connections at the switch and fixture. Otherwise, call an electrician.