Android applications can be executing or debugging in either virtual device or real device. But it can be executed or debugged in only one device at the same time. This article will show you how to do that.
1. Run / Debug Android App In Virtual Device.
- Setup and launch a virtual device simulator, you can read the article How To Create Android Virtual Device (AVD) In Android Studio to learn more.
- Select the activity java class that you want to run/debug from the top toolbar drop-down list. Click the run button ( green triangle ) to run it or click the debug button ( green triangle on a bug ) to debug it.
- You can also right-click the activity class in the android studio left project view panel, then click the Run / Debug submenu in the popup menu list to run / debug the android activity.
- Then Select Deployment Target window will pop up, there are two sections in the list, one is Connected Devices the other is Available Virtual Devices.
- Select the device you need from the Available Virtual Devices list. Click the OK button. If the selected device is not started up, it will start up a virtual device simulator automatically.
- Then the AVD simulator will startup and the android application will run in it.
2. Run / Debug Android App In Real Devices.
- You need to enable USB debugging mode in a real android device first. Please read the article How To Enable USB Debugging Mode On Android Device to learn more.
- Connect the physical device with the PC using a data line.
- Run / debug the selected activity java class, choose the real device in the Select Deployment Target window Connected Devices area.
- Click the OK button, then the Instant Run dialog popup, click Proceed without Instant Run button. Then the app will execute on your real device, you can see the result on the real device’s screen.
- If you want to learn more detail about debugging the android applications, please read the article Debug Android App With Android Studio Examples.