adb (android debug bridge) is a command line tool which lets you communicate with your usb connected android devices or android emulators. Here are some handy commands to use adb. We used mac for the purpose of this tutorial. Note that you must enable USB debugging on your android phone for adb to work.
List devices
To list all devices connected to your machine and emulators running on your machine:
$ adb devices List of devices attached 013884750301A00A device emulator-5554 device
Get shell on device
To run a shell on device connected to usb run the following
$ adb -d shell
To run a shell on only emulator run the following
$ adb -e shell
In there there are two or more emulators, you can specify the specific one using -s
$ adb -s emulator-5554 shell
Install apk using adb
To install an apk file on connected device, run the following
$ adb -d install -r app.apk
start an app on connected device
Activity can be started using shell and am (activity manager)
$ adb -d shell am start -a android.intent.action.MAIN -n com.foo.myapp/.MainActivity
Stop an activity
To stop an activity run the following
// com.foo.myapp is package name $ adb -d shell am force-stop com.foo.myapp
view android log
To view logs on connected device
$ adb -d logcat // or $ adb -d logcat -f out.txt
Note that using -d or -e option is pretty handy way to connect to connected device of emulator if only one device is connected or only one emulator is running. Otherwise you will have to first print device id and then connect to that device.