I’ve been a big fan of JetBrains’ products for a long time, especially their TeamCity build server…but more on that later!
To get started on Android development, head over to Google and download the SDK (version 1.6 at time of writing). Extract it to a location of your choice!
Create a new project in IntelliJ, selecting an Android module and give it an appropriate name.
On the next screen, the default os to create a ‘hello world’ activity. The default package is com.example, which you’ll want to change for future projects (I’ve yet to track down where it is set in the preferences..).
The hello world activity is a useful starting block when learning how the basic Android components work, or just starting a new Android project, since it will set up the basics for you.
You’ll also need to set up the Android SDK against the project in the top section, add and browse to the location of your downloaded SDK. I suggest setting the platform level to Android 1.6 (you’re able to select 1.5 or Google APIs as the platform if you wish. Google APIs gives you some extra functionality such as the Maps external library).
The generated project structure looks a little like this:
The R.java class is auto-generated each time you build the project. It contains references to the resource files in your project, contained under the res directory.
It is not intended to edited (any changes you make would be overwritten on the next compile).
The resources directory, res, contains all the non-java resources that make up you application, including image and string resources, layout definitions and other configuration xml files.
For example, main.xml under the layout directory contains an xml definition of the screen layout. Pretty simple really, just a layout container and a text label (see xml below). The TextView element specifies its text attribute as “@string/hello” – a reference to strings.xml, and the value of the hello element.
The java file MyActivity contains just enough code to tell the application to write the contents of main.xml to the screen.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout>
<resources> <string name="hello">Hello World, Lop!</string> <string name="app_name"></string> </resources>
To run your shiny new application, you have to set up a virtual device to run it on.
The SDK prvides a tool – <SDK>/tools/android – that works as a GUI and command line interface to manage devices.
You can manage the devices through IntelliJ also – edit the run configuration (which was automatically generated for you), and click the ellipses to the right of the drop-down.
I prefer to use the Google utility, because I find the AVD will take a minute or two to start up, and so I’ll launch it when I open my project, not when I want to run my application the first time.
Once your AVD is configured and running, you should be able to launch your application, and see your friendly message!
Check out some of the tutorials in the developer guide of other basic components that are available.
And also, read the application fundamentals to get your head around the Android architecture!