Archive for category getting started

Android 101 – The basic building blocks of an Android Application


This post talks about the basics and fundamentals of Android development. So if you know java and eager to program for the Android platform, read on.

I recently developed an iOS app for a large organization and published it on itunes. Received some good feedback, however, turns out that half of the users have Android phones. So i started looking at developing an Android version of the iOS app. Plus according to Google, more than 350,000 android devices are being shipped on any given day which translates to 1 million new Android users every 3 days!

Compared to iPhone, Android has quite a few vendors shipping different kinds of Android phones (LG, Samsung, Motorola, HTC, etc.). However, good news is that now there is a one common platform on which to develop Android apps – the latest one is called honeycomb 🙂

So lets start with the basics. And Android app is a collection of several different components viz. Activity, Service, Content Provider, Broadcast Receiver, Intents; all of them are defined in AndroidManifest.xml.

1. Activity – This is how you write an Android user interface. A single activity defines a single screen with a user interface. When you write a user interface for your home screen it will most likely extend the Activity class. It defines simple lifecycle methods like onCreate, onResume, onPause which lets you handle interruptions.

2. Service – it does the majority of processing for your application. Its the logic behind the user interface. E.g. performing a long running process in the background. You can sub class the Service class to write your own custom service.

3. Content Provider – This provides a uniform singular interface to the content & data. The content can be from your app being exposed to the system or other apps or it could be system content e.g. pictures on your phone, contact lists exposed or available to your app via the Content Provider interface. It provides a consistent interface to retrieve/store data via RESTful model supporting CRUD operations.

4. Broadcast Receiver – The application modules communicate with each other using the broadcast receiver. Messages can be initiated by the system or the app. E.g. if a user is using your app and a phone call comes in, the Broadcast Receiver interface will notify your app and your can code to handle that interruption (by possibly delegating to your service). You can opt to receive messages statically via declaring in the manifest file or dynamically by programmatically registering it the code which extends the Broadcast Receiver interface.

5. Intents – Of all the main components we discussed so far, this is the most interesting. Intents can be implicit or explicit. E.g. an explicit intent can be to invoke another screen when a button is pressed on the Activity (UI) in context. An implicit intent is when you create an intent and hand it off to the system to handle it. A good example discussed in one of google I/O boot camp was the barcode example, where the app creates an implicit intent of type SCAN and provide it to another app which handles scanning and returns the resultCode back to the calling application.

Typically you define all the components of your Android app in the manifest file. You can state the features, permissions and sdk version in the manifest. The application tag will have sub tags defining activities, services, receivers and intents.

Having discussed the main components, lets move on now to our first basic task – creating a simple user interface.

In the Android World a UI is a hierarchy of Views and ViewGroups which can be defined either programmatically or in XML layout files. E.g. to create a simple linear layout i can define the following in my xml file (e.g. main.xml under the layout folder of your application resource package):

<?xml version=”1.0″ encoding=”utf-8″?>

<LinearLayout …>

<TextView android:id=”@+id/text”

android:text=”Hello World!” …/>

</LinearLayout>

Though we used linear layout here, its considered best practice to use RelativeLayout to cater for multiple size screens.

In the next post we will use the above discussed concepts to build a simple Android application.

Feedback and Questions are appreciated.

, , , , , ,

Leave a comment

Installing Heroku CLI and Git …in 10 minutes!


If you are planning on playing with heroku, this post will help you get started in setting up your local machine with heroku CLI (command line interface) and Git (open source cloud based version control system).

Note that this post is a simplified and more detailed version of heroku quickstart article available at :

http://devcenter.heroku.com/articles/quickstart

Update — If you are using Mac OSX, you might want to just download the Heroku Toolbelt (http://toolbelt.heroku.com) The toolbelt (heroku CLI & Git ) will provide you everything you need to get started using Heroku!

Steps

1. Download Git for your OS and sign up for free Git account http://git-scm.com/download

2. A Heroku user account. Signup is free and instant.

3. Since heroku CLI is a ruby gem, in order to install it, you will need to install ruby locally on your machine.Installing the latest Ruby version with RVM is simply done by typing :

rvm install 1.9.3.

Note that if you do not have rvm installed, you can install it on mac/linux by:

$ bash curl -s https://rvm.beginrescueend.com/install/rvm.

You might need to prefix the    command using sudo ($ sudo curl -s https://rvm.beginrescueend.com/install/rvm)

4. Ensure that you have ruby installed by typing ruby –version

5. Using command line install heroku by typing:

$gem install heroku

Note that this will prompt you for your heroku credentials (which you used at step 2). After this step is finished your email address and API token will be saved to ~/.heroku/credentials

Also note that you might want to prefix the command with sudo (sudo gem install heroku) to make the command write the gem to the destination directories. If this still fails, try running:

$sudo gem install addressable

and then execute $sudo gem install heroku

6. It’s generally a good idea to add your public key immediately after installing the heroku gem so that you can use git to push or clone Heroku app repositories:

$heroku keys:add

sample output:

Enter your heroku crendentials:

Email: ssharaf@salesforce.com

password:******

Uploading ssh public key /Users/ssharaf/.ssh/id_rsa.pub.

7. At this point, you should be ready to start playing with the coolest PAAS (platform as a service) aka heroku!

Note that for application development you might want to install maven and OpenJDK v6 (for Java)

, , , , ,

Leave a comment