The Swedish Public Health Agency has developed national criteria for assessing freedom from infection in covid-19. The PCR technology used in tests to detect viruses cannot distinguish between viruses capable of infecting cells and viruses that have been neutralized by the immune system and therefore these tests cannot be used to determine whether someone is contagious or not.
RNA from viruses can often be detected for weeks (sometimes months) after the illness but does not mean that you are still contagious. There are also several scientific studies that suggest that the infectivity of covid-19 is greatest at the beginning of the disease period.
The recommended criteria for assessing freedom from infection are therefore based on stable clinical improvement with freedom from fever for at least two days and that at least seven days have passed since the onset of symptoms.