The easiest way to prevent this is to invest in good anti-virus or malware. Another way is to get on only protected websites and not get into any suspicious sites or use those apps. Keeping a regular backup of important files is a must.