The misunderstanding of whether or not Sri Lanka is a safe country to visit still stay which is quite justified due to harsh civil war between 1983 and 2009. It is true that most tourists kept away during this phase but after the end of the civil war, this is completely a different phase altogether.
With friendliest people, Sri Lanka is a remarkably safe place to travel in and violent crime against foreigners is almost unheard of. However, take the necessary measures to ensure safety by avoiding conversation that include topics like politics and religion, walking alone after dark, keeping your valuables like money and passport in safe place, avoid rallies and huge public gatherings etc. It is also wise and cautious to avoid smoking and drinking in public places as it is against the law.
Side-step from taking any kind of photos or filming around High-Security Zones like all military establishments and some government buildings, including official residences and also you are advised not to pose for a photograph next to a statue of Buddha. Make sure to keep updated about weather or any kinds of natural disaster constantly. It will help you take any kind of necessary action immediately. If you are going to the beach, make sure you are not alone and at know how to swim.
Besides being cautious about smallest details, it is also smart if you plan well, read travel advices from experts - you will find many in websites. And leave a detailed itinerary with someone at home and try and keep in regular contact with details. Paying attention to these smallest details will surely help you avoid getting into trouble and ensure safe trip.