Friday 27 July 2012

Running the Android Application

After we have created an application we would want to test and run it, obviously !

So now lets see how we can do so. We first create a sample hello world program and then run it.

While using the Eclipse IDE you would see that the project wizard by default provides us with a ready made, ready to run Hello world program. That means that we already get the following:

  • layout - The graphical user interface(GUI)on which we see the output and interact with our application.It is a .xml layout file.It is located in the directory workspace\your_application\res\layout\activity_main.xml
  • src - The .java class which has the code and all the logic enables us to interact with the GUI. It is located in the directory workspace\your_application\src\com\tutorial\example\MainActivity.java 
  • Android manifest - The .xml file which enables us to debug our application.Without this the debugging can not be done.It is located in the directory workspace\your_application\AndroidManifest.xml
  • string - Is a .xml file that helps us to reference resources by using the name attribute of it.It is located in the directory workspace\your_application\res\values\strings.xml.
So the ready made code that we get is :
MainActivity.java

public class MainActivity extends Activity//Create a new activity
{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);// Set the content on a particular layout .
    }
    
}
String.xml

<resources>

    <string name="app_name">examples</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>

</resources>

Android Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tutorial.example"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="6"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

so without even writing a single line of code we get this.:)

Running application on AVD:

  1. Go to window in the Eclipse IDE
  2. Select AVD manager
  3. create new AVD
  4. Set the properties for the AVD
  5. Click create AVD
  6. Next, go to your application 
  7. Right click on it and select "run as"
  8. go to run configuration
  9. now in the new window that opens up create a new configuration 
  10. set the target device as the AVD that you just created 
  11. Click apply
  12. Click Run.

Running application on a real Android Device:

First of all make sure that you install the drivers of your device on your PC.Then follow the following steps:
  1. Connect your device to your PC with the USB cable .
  2. Mount your android device.
  3. On your device go to settings>>Applications>>Development
  4. Enable USB debugging.
  5. Next, go to your application 
  6. Right click on it and select "run as"
  7. go to run configuration
  8. now in the new window that opens up create a new configuration 
  9. set the target
  10. select the radio button"Launch on all compatible devices/AVD"
  11. Select "active devices"

Monday 23 July 2012

Creating A Beautiful Samsung Nexus S AVD

Bored with the traditional android AVD I wanted to run my programs in the new screen so I tried the new Samsung Nexus S skin .

If you wish to do the same just do the following steps and you'll be done :


  • Download the NEXUS-S skin from here
  • Unzip the file and locate it the "platforms" folder inside the android SDK folder 
  • Inside the platforms folder you will find  a folder for Skin 
  • Paste the unzipped NEXUS-S file into the skin folder 
  • Now go to eclipse
  • windows>> AVD manager 
  • click new to create a new AVD
  • Now you select the NEXUS-S skin 

now we are good to go and run our application on the new NEXSUS-S skin :)




My Tutube video for the same:


Tuesday 17 July 2012

Creating Android Virtual Device(AVD)

To test and see how our application looks like we need a Android Emulator, so what we need for that is to configure our AVD .And for creating an AVD we need to set the properties for it . So lets see how to go about it:

Lets split this mission into 2 parts :

Part 1: Creating a AVD

 Go to Window in the Eclipse IDE>> Select AVD manager

or

Click on the AVD manager icon on the toolbar
Next you would see a screen like this:


Set the AVD properties >> Click Create AVD

An important thing that I would like to mention here carefully set the size of the AVD's SD card . Although you can set it to a  minimum of 9MiB but I would suggest you to allot it reasonable size to the SD card, and yes this SD card space is allotted on the computers hard drive.

Part 2: Using the AVD


Now in order to see how to use a AVD we must have a project already created and ready to be run. 

Running the application for the first time we need to do the following:

Right click on the application you wish to run >> Click run configuration >> set the name of the Configuration>> Select the application you wish to run>> Set the target (which is the Emulator on which you wish to run your project)>> click Apply >>Click run>> Emulator starts.




Exploring Eclipse

Just as always we create our new project in the Eclipse IDE .

Go to File >> New>>Project and you will see a Screen as this :

Select Android Application Project>>next>> Specify the Application name >>Specify the Project Name>>and finally specify the Package name>> Click next>>Click next>>Select Blank Activity>>specify activity name>>Click Finish


Okay so far so good !


Downloading and Installing Android

Taking the first step in the android world . lets Download the Android SDK for your operating system. To do so by visiting the official site for the download  here.

Read the instruction to install the SDK from this site.

Add the Platform and the packages.

In case if you are wondering that :
What is Eclipse ? and why do I need it for android development?

Here is the answer Eclipse is an Integrated Development Environment (IDE) for multiple languages. And the best part of it, is that it's FREE :) and open-source, also it can be extended by adding new plugins to it .So for using eclipse for android we need to add the android plugin to it.

Download Eclipse indigo from here

Install the Eclipse plugin.
Now we are good to go to the coding part of mission . :)

Say hello to the Android World



It being my summer break  time I am at home trying my hands at new technology ... and as usual trying to learn something about which  I have least idea , yeah I am talking about android .development.

Last year I got a new android phone and ever since i got it i have been wondering how amazing it is .The amazing applications available at the Google play  or the android market make my heart go boom boom ...:)

Although I have a bit knowledge about Java I had to struggle to get it going, right at the beginning few days earlier when I started with the download and installation(credits to my slow bb), but then I realized it's not that difficult to do it ... in fact I would say it is pretty easy. And I think that I was lucky to have faced all those problems, as it made me search, explore and learn more . I remember once my professor at college said that "If you are lucky you would get many errors and problems learning new technology ... but if you learn it in-spite of those thing you learn it in true meaning "

Now, having created a few applications of my own I would be ore then happy to share my learning with you .So in the coming posts we would discuss all the steps we need to follow  to create a new android application .