Wednesday, March 23, 2011

Start Androiding....

Hi,

In this post, we'll try to cover following things:
  • Some things to look upon before starting
  • Creating simple test project
  • Run it on emulator/device
I assume that android environment is set in your machine; if not goto setting android environment
Now open eclipse and create new project by clicking
                            File->New->Project
Under Project heading choose "Android Project" in Android Category and press next. you will see the following screen.

Now fill the properties like :

                       Project Name          = HelloWorldProject
                       BuildTarget              = any; i choose Android 2.1-update1
                       Application Name    = Hello World App
                       Package Name        = com.HelloWorld
                       Activity                    = HelloWorldActivity

I add property names in the end of each property value to distinguish them. Later you can check, which file goes where...
Press Finish and you have successfully created your first project. Simply right click on project name from project explorer view and click build; there should be no errors in the project.

Creating a virtual device:
To create a virtual device; Goto Window->Android SDK and AVD manager, selecting virtual devices a new window will open. Select new and set name and platform for the device, give size of sd card like 24/32 MB and press "create AVD". A new virtual device has been created. Select this device and press start. New Virtual device will run.

Now coming back to our project, right click on the project again and click RunAs->Android Application... our application will install on this virtual device and it will run automatically. if you didn't start the virtual device then by clicking RunAs, it will select appropriate virtual device by checking the platform of application.

Output will be like this:

Now lets talk about some things... :)


Things to look into:
  • Activity class
  • layout file
  • manifest file
For every application having a GUI, there should be a class which extends from Activity. so Activity is the class given by android which handles the screen or gives you the full screen and you can set controls/views on this. Lets c what our class looks like...


package com.HelloWorld;

import android.app.Activity;
import android.os.Bundle;

public class HelloWorldActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

as you can see our class extends from Activity which is responsible for handling GUI components. Every activity is started by calling its onCreate function or you can say that from onCreate function the scope of any activity starts. when we extend our class from Activity; it by default inherits its create/destroy functions and we have to override them in order to meet our specifications, like we have to set any control/view in our window then we would override onCreate function and set our window but still we needs to call its original onCreate function as shown in code above:
                 super.onCreate(savedInstanceState);
Please also read the official documents about activity from here: Reference document for Activity

This line adds functionality and sets a layout to our window:
                setContentView(R.layout.main);

Now the design of the screen is created by two methods; from xml or from code. In res/layout/main.xml you will see something like this:

<?xml version="1.0" encoding="utf-8"?>
<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>

First you have to set a layout for your screen. Android provides 5 to 6 layouts, i have mostly used LinearLayout i.e all controls will be added up linearly one after another (horizontally or vertically). you can check further details from here: layout-objects

As shown above, we have add a TextView control in our layout, similarly we can add different controls. open main.xml and switch to graphical layout and you can see different controls. You can also change the properties of any control, a TextView in our case, by switching to graphical layout and look for properties view; if not found, simply add it from Window->Show View->Other->General->Properties

In Menifest.xml file, we declare application icon, app name, activities and permissions which our application uses like 'internet'.

That was all.... I try my best to get you start easily but still if you find anything difficult, leave a comment.

Regards,

5 comments:

  1. Good job done boy.

    Best of luck..

    ReplyDelete
  2. worth a go for android beginners... a job well done ... :)

    ReplyDelete
  3. please add an example to add 2 numbers !! and how to get the result on pressing a button ??

    ReplyDelete
  4. ok i'll write a new post for the example... :)

    ReplyDelete
  5. É PEDOFILO SATANISTA ASSASSINO: #ANDREABAGGIO ANDREA BAGGIO DI CRIMINALE REPUTATIONUP CASTELFRANCO VENETO!
    1
    OLTRE AD ESSERE FIGLIO DI PUTTANA HITLERIANO, TERRORISTA LEGHISTA, RAZZISTA, NAZISTA, OMICIDA E RICICLA SOLDI NDRANGHETISTI DI COSCA ARENA DI ISOLA CAPO RIZZUTO (DI CUI É PARTE PURE IL MASSONE NOTORIAMENTE NDRANGHETISTA #PASQUALECATERISANO PASQUALE CATERISANO, CHE RICICLA SOLDI MOLTO LERCI IN CRIMINALISSIMA Polizza-vita.net, LO TROVATE QUI https://it.linkedin.com/in/caterisano E QUI https://pasqualecaterisano.it, PUBBLICIZZA CRIMINALISSIMA FACILE.IT, PERCHÉ VENDEVA COCAINA E MEGA SNIFFAVA COCAINA COL MASSONE STUPRATORE #ALBERTOGENOVESE ALBERTO GENOVESE, PER FINIRE, IL SATANISTA OMICIDA #PASQUALECATERISANO É BASATO A MILANO, MA É DI NDRANGHETISTISSIMA, CALABRESE ISOLA CAPO RIZZUTO, DOVE É STATO AFFILIATO, BEN APPUNTO, AGLI ASSASSINI DI MEGA OMICIDA COSCA ARENA). PRESENTISSIMA A CASTELFRANCO VENETO
    https://www.trevisotoday.it/cronaca/operazione-ndrangheta-castelfranco-febbraio-2021.html
    IL PEDOFILO OMICIDA ANDREA BAGGIO DI CASTELFRANCO VENETO É MALAVITOSO, MA COME DETTO, É PURE UN MASSONE SATANISTA. HA UCCISO ALMENO 20 PERSONE PER RAGIONI CRIMINALI VARIE. SIA PER LA COSCA ARENA DI ISOLA CAPO RIZZUTO, COME PER LA COSCA NDRANGHETISTA DI SAN LEONARDO DI CUTRO (NE TROVATE SEMPRE QUI https://www.trevisotoday.it/cronaca/operazione-ndrangheta-castelfranco-febbraio-2021.html). HA FONDATO LA SETTA SANGUINARIA "SATANISTI LEGHISTI ASSASSINI" SEMPRE BASATA PRESSO CRIMINALE SEDE DI #REPUTATIONUP, IN VIA DEI PINI 21, A CASTELFRANCO VENETO (DI CUI É PARTE PURE IL MASSONE ASSASSINO #OSCARDIMONTIGNY OSCAR DI MONTIGNY DI CRIMINALE BANCA MEDIOLANUM). SON SCOMPARSE ALMENO 50.000 PERSONE, IN VENETO, DAL 1970 AD OGGI. DI SOLO UNA PARTE, NE PARLA IL CORRIERE DELLA SERA QUI
    https://corrieredelveneto.corriere.it/vicenza/cronaca/21_giugno_13/vicenza-scomparsi-nulla-mai-ritrovati-5-uomini-svaniti-monti-d7eb8d98-cc3e-11eb-9d75-52aabbbee8c5.shtml
    (CORRIERE DELLA SERA, D'ALTRONDE, DA SEMPRE PIDUISTA, DI FINTA PROPRIETA' DEL MASSONE CRIMINALE #URBANOCAITO URBANO CAIRO, IN REALTÁ, PRESTANOME DEL PEDOFILO STRAGISTA #SILVIOBERLUSCONI SILVIO BERLUSCONI E DELLA LESBICA SATANISTA DEPRAVATA E MANDANTE DI OMICIDI #MARINABERLUSCONI MARINA BERLUSCONI… CORRIERE OVE RAGLIA FASCISTATE, UN’ALTRA COCAINOMANE, TERRORISTA DI ESTREMA DESTRA E LESBICA MOLTO PEDOFILA: #MARIATERESAMELI MARIA TERESA MELI)
    NEGLI ULTIMI 10 ANNI, IL SATA卐NAZISTA ASSASSINO, IL PEDOFILO KILLER ANDREA BAGGIO DI REPUTATIONUP, HA ALMENO RAPITO 30 BAMBINI, PER POI INCULARLI, UCCIDERLI E VENDERNE GLI ORGANI. NE SCRIVEREMO OGNI GIORNO, NIGHT AND DAY, SU TUTTI I SITI DEL MONDO. CHI SCRIVE É PARTE DI EROICA ASSOCIAZIONE PENELOPE, CHE SI BATTE CONTRO MASSONI SATANISTI PEDOFILI ED ASSASSINI COME #ANDREABAGGIO DI #REPUTATIONUP!

    ReplyDelete