The procedure you need is actually the debugging one and you should follow all the instructions recommended for the debugging process.
Also, the code executes based on the way you've developed it in Android Studio and not the other way around unless errors appear, but even then the app should stop.
Here is a search query related to your needs: https://goo.gl/tzaAEj