Last time on the “Let’s All Learn How to Develop an Android App” channel, we took you through the set-up of your development environment — no, not ensuring you have enough Monster munch to hand; instead making sure you’re ready to start coding your own application. We also asked for your suggestions of potential projects we could use over the course of these articles, and the response was…pretty immense, if we’re honest.
We’ve sifted through dozens of suggestions, but one that really caught our attention was to create a proper Giz UK app that would deliver the best of our content to your mobile device of your choice. This might be a bigger project than we can cover in detail, so what we’ll do is take you through the concepts of coding and go into detail on some of the key areas of code that the app will need — then it’ll be down to you to take our teachings and turn them into something truly wonderous…who knows, if your creation is any good, maybe Kat and the team will keep you in gadget freebies for life, as thanks. (Ed — freebie iPhone 4 cases, anyway…)
Different coders have different ways of starting their projects, but take it from us — if you don’t plan what you’re doing BEFORE you start, chances are the end result will suffer. You can plan in many different ways, and everyone has their own preference — some use ‘pseudo code’ to lay down the basics of their software; others put pen to paper, and others use various wireframing tools to mock up the app before typing even one line of code. You need to decide which approach is best for you.
At a basic level, our app is going to read the Gizmodo UK RSS feed and display the headlines for you to click through to the article on the Gizmodo UK mobile site. It sounds quite straightforward, but there are a number of things to consider:
- Will the app poll at regular intervals for new content, or will it require a user ‘refresh’?
- Will there be a minimum amount of time between content refreshes?
- Do we want to just display the headline, or do we want an image?
- Do we want an excerpt, or the full article?
- How many articles will we display?
- What ‘permissions’ do we need to assign the app?
There are countless other questions, so brainstorm and think of as many things as you can that you need to answer before you start. I’ll do my best to help out in the comments field below.
The app I’ll be developing here will be kept as simple as possible — we’ll have a Home Page and a Settings Page, and articles will only be refreshed if the user pushes the refresh button. We’ll only allow content refreshes at a minimum interval of five minutes to prevent the app from sending requests to the server too often, and we’ll show the most recent ten posts on the site.
Once you’ve planned out your app, the next step is to open up Eclipse and get yourself ready to code. Once Eclipse has loaded, go to File > New and select the option ‘Android Application Project’. There is a simple wizard that takes you through the first steps — we’ll largely use default options for now. The first page requires you to set up your application name and basic settings…
Click ‘next,’ and on the next page just accept the default settings and move on. Now you can create a custom icon for your app. For ease, we’ve used the inbuilt Eclipse tools to create a simple G icon which took a matter of seconds, but you can be as creative as you like. There are some basic iconography specifications that you need to meet for your icon to be acceptible.
Once your icon is complete, the next step is to create your main ‘Activity’. Android applications are broken down into ‘Activities’ which are effectively individual programs that are linked together to form the larger app. Most apps are centred around one main activity and ours will be no different — ours will be a list of recent Giz UK updates. With this in mind, we’ll go with the defaults again and select the BlankActivity template before clicking next.
And, that’s it — you now have a basic Android app that you can start to populate with content and functionality.
We’re nearly at the point where we can run your app for the first time, and so far you haven’t had to write one line of code. Before we get that far though, there are a few more things you need to learn about:
The manifest is a kind of configuration file. It defines a number of aspects of your app ranging from permissions through to the SDK versions you specified earlier on. Eclipse gives you a handy Manifest editor that allows you to edit the file without too much hassle. Double click on the AndroidManifest.xml file on the Package Explorer to launch the Manifest editor. The editor is split into a number of tabs, displayed at the bottom of the window.
Android Virtual Device
The AVD is basically an emulator; it allows you to run any app you’re developing on your PC as if it was running on a mobile device. To create an AVD you need to follow these steps…
- Click the ‘Android Virtual Device Manager’ icon in the Eclipse toolbar.
- Click ‘New’ to create a new device.
- Enter an appropriate name – we’ll go with ‘JellyBeanEmulator’.
- Select the closest device to your development hardware — we’re using a Galaxy Note II, but that isn’t an option, so we’ve selected the Galaxy Nexus which shares the same 720 x 1280 screen resolution.
- Our Target device runs Jelly Bean 4.1.2, so we’ve selected that.
- We’ve chosen an ARM CPU and left everything else on the default for now.
Click OK, and we have a nice new Android emulator. Select it from the list and then click Start; after several seconds you should have what appears to be a reasonable replication of a mobile device right there on your PC!
Once the emulator is up and running, you can tell Eclipse to compile and install it — just click on the ‘Run’ icon and select Run As… Android Application. After a few seconds, Eclipse will have installed the app within the emulator and it’ll be available for you to run. Browse the apps until you find yours, select it and be instantly impressed at your EP1C d3v3l0p3r Sk1Llz! Or something to that effect…
Colin Polonowski is a developer at Giz UK’s parent company Future Publishing, working across a number of their sites. He also runs The Digital Fix in his spare time. Check in on the 18th of April for his next App Millionaire guide.
To get on-the-spot news, app tips and the full lowdown on Samsung’s latest mobile announcements check out Samsung’s Your Mobile Life over here.