Showing posts with label running. Show all posts
Showing posts with label running. Show all posts

Monday, January 19, 2015

Android beginner tutorial Part 4 Running and debugging applications

Today well learn how to run and debug our application.

There are two ways to run our Android application - using an emulator, and using a real Android device that is connected to the computer.

First Ill explain how to install and run the application on a real Android device. Connect your device to the computer using a USB cable. You might need to install proper device drivers to do this correctly. Take your phone/tablet, launch Settings > Applications > Deevlopment, then make sure USB debugging item is checked.

Open your project in Eclipse, then in the menu select Run > Run. A window will pop up asking you to select a device or an emulator. Select your device, and click OK. Your application will be installed and launched on the device! By default its a simple screen with "Hello World" written on it.

Youll also find your application in the menu of your device, with the icon and title youve set. You can launch it from there as well.

The second way to run an application is using an emulator. Go to Window > Android Virtual Device Manager in Eclipse. Hit New, set the name and settings for your virtual device. Youre free to play around with the settings, if something is entered incorrectly - you will be informed of the error. When youre done, click OK.

You can now see your device in the list of the Android Virutal Devices tab in the dialog window. You can start it now by selecting it and hitting "Start". Youll have to wait for the system to boot on the virtual device before you can use it. Then you can look around the phone/tablet almost like its real.

Then go to Run > Run, and select the virtual device you have to launch your application there. If you didnt start your emulator before, you can do it here by ticking "Launch a new Android Virtual Device" radio button and then selecting the AVD.

And thats all you need to do to launch your application!

However, when developing programs, you might need more advanced debugging tools than just an error console.

There are 2 ways to debug Android applications in Eclipse - one is using the java debugger, the other one is using the DDMS (Dalvik Debug Monitor Server).

To use the java debugger, open Eclipse and go to Window > Open Perspective > Debug. Youll find a new button in the top right sector of the Eclipse IDE window labeled "Debug", located near Java button.

Launch your application if it isnt already launched on either your real device or an emulator, and youll see some activity taking place in the left section of the debug screen. You can select items there and manipulate things like Variables on the right side of the screen. If its just a simple application like our Hello World, there wont be much to do (or there wont be anything at all to debug).

The Debug feature includes Variables, Breakpoints and LogCat, which are tools that you can use to see values of variables, breakpoints, as well as system log messages in real time.

The Dalvik Debug Monitor Service is a tool that is included with Android SDK and is not present in Eclipse by default.

It can be launched the same way - Window > Open Perspective > DDMS. Youll quickly see that its more advanced than the standard Debug tool and includes more features. It gives you control of many Android-related objects and processes. You can even explore the files of the device. Its rather complex for me to explain all of its features, I suggest you head over to the official documentation page for DDMS if you want to explore all of its features.

And thats it for this tutorial!

Thanks for reading!
Read more »