It can arrive in several ways. First, it could be installed deliberately by someone else to track you. That's one reason you need to use the screen lock capability on your phone - don't leave it sitting around and open to interference. More likely, the spyware accompanied a program or app that you installed yourself.