How To Get Started with Android Development
Cindy Potvin provides a quick primer for beginners on how to develop for the Android platform.
Join the DZone community and get the full member experience.Join For Free
learning how to build a mobile application is a good project to improve your programming skills while learning to work in a different environment than the desktop or a web browser. you can get started without worrying about a large stack, making it easy for a beginner to pick it up and start playing with quickly.
building applications with the android sdk is self-contained if you stick with the standard libraries. you only need to download the package from google containing all the tools and you’re ready to go. if you know object-oriented programming and how layouts are done for the web, many patterns and practices will feel familiar to you. the barrier to entry is low: all the tools are free, so you only need an android device and your computer to get started.
also, the open philosophy of android means that you can do as you wish with your applications and your device. as long as you have an installer file (.apk), you can distribute your application to any device. it’s easy to send a copy of your application to your friends so they can test it out. this is great if you have a small project that you only want to deploy on a few machines such as a kiosk an art project. once you have more experience, there are many open source libraries that improve on what is available in the sdk, and the open source community is active and welcoming.
the following will teach you how to get up and running with the samples included with the android sdk.
setting up an android development environment
you don’t need much to get started with android. any decent pc, mac or linux box will do the job. all the tools are free, and you can install them as a single package from the google android developers site at https://developer.android.com/sdk/ .
there are two main tools you need to know about: the android sdk manager and the android studio ide.
the android sdk manager is used to download the libraries, tools, system images and code samples for the platform (version) of the android os you want to develop for. by default, the package contains the latest version of the sdk platform (6.0/api level 23 as i’m writing this). when a new version comes out or a new developer kit is available, you must download it using the sdk manager.
the android studio ide is where you’re going to spend most of your time. it is based on intellij and includes a code editor, a layout editor and all the tools you need to compile your application and debug it on an emulator or on your android device. eclipse was previously available as an ide so you’re going to see some references to it online, but android studio is now the official ide for android and everybody is now using it.
installing the drivers for your tablet
by default, when you plug in an android device in your computer, you’ll see the content of the external storage like you would see the content of a usb key. it’s enough to upload data, but if you want to debug an application on your device, you must install the drivers. you could develop applications using the emulator, but it’s a lot slower and it’s going to be hard to see if the touch interactions work as you intended.
if you have a nexus device, the drivers are available from the android sdk manager. for other manufacturers like samsung or asus, you can find the driver on their website. it’s not always clear what you should download, since the driver is often packaged with other software such as synchronization tools.
to be able to attach a debugger, you must also enable the debugging mode on your device by navigating to the about option in the settings menu. click 10 times on about and the developers options menu will appear, allowing you to set the debugging mode.
running the sample projects from the android sdk
the language used with the android sdk is java, but android has its own virtual machine, dalvik, that uses a subset of the standard java classes. since it’s such a small subset of java, you don’t need experience in java to get started. if you have a good basis in any object-oriented language, you should be able to pick it up pretty fast. the rest of the files, such as language files and layouts, are in xml.
to get started quickly, i’m going to show you how to run one of the sample projects. those samples are from google and they are a good starting point to learn what you can do in an android application and how to do it. google regularly adds new samples as new apis becomes available, so check them before trying to do something.
when you start android studio for the first time, you’ll see the following screen. to get started running an application right now, just select import an android code sample to create a project.
in the following screen, choose the borderless button example and click next to create the project:
once the project is loaded, select debug… from the run menu to launch the application in debugging mode on your device. a device chooser window will pop up, allowing you to select your device (if the driver has been properly installed) or to launch the emulator. press ok and the sample will run on your device.
you can now play with the sample and add breakpoints in the source code (located in the application\src\ folder) to see how it behaves. for example, you can put a breakpoint in the oncreate method of the mainactivity.js file, and try to understand how it behaves when you rotate your device.
Published at DZone with permission of Cindy Potvin, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.