If the pain does not start suddenly, it is a sign of Osteoarthritis.
It can be due to Chondromalacia patellae, which is treated the same in both cases. Rest in pain. Fasting and light exercises after the pain is over. Sit on a chair and gently straighten your knees. 15 times on each leg and hold for 5 to 10 seconds each time the knee comes up. Gradually use the elastic for more pressure after a few weeks of training.