Fundamentals of Android application development part 2

Fundamentals of Android application development part 2

In one of  previous post we looked at android application development part 1.  In this article we will explore android platform fundamental application development components in more details.

User Interface Layout

User Interface Layout  are specified in XML files.  Some tools allow use to create the application layout visually.

Layout files are typically stores in Res/Layout/*.xml location e.g main.xml

Layout can be accessed in Java code files by using R.layout.layout_name. In other resources we can access as @layout/layout_name.

We can create multiple layout files and android will choose can choose from layout file based on device’s configuration.

If our device is in landscape mode then it can have a Layout-land/main.xml.

What is R.Java file?

At compilation time, resources are used to generate R.Java class. Java code uses R class to access resources. This file is generated by android so  we should not modify it. file sample code

R class defines another class “layout” that has a field called main. That actually give a reference to handle main.xml file.

Implementing Classes

Implementing java classes is the next step in Android Application Development. It involves at least on Activity.  Activity initialization code is typically inside onCreate method.

onCreate Method

In on create method we normally do following 4 things.

  • Restore saved application state
  • Set the content view which tells the android what to display as the activity user interface
  • Initialize the UI elements
  • Link UI elements to Code Actions – So specific actions will be performed when user will interact with these UI elements.

android oncreate

In onCreate method we first call super.onCreate() and pass it savedInstanceState parameter of type bundle typically a data structure containing any  information that  android might have saved from the last time activity was running. onCreate method has to call super.onCreate or other wise we will get an error.

Net there is a call to setContentView. In this case we are passing the reference to the layout file for this application.

Packaging The Application.

Next step in android application application development is that system packages the Application components and resources into and .apk file. This all information is written in an XML file called AndroidManifest.xml. file.

This file contains name of the application, list of Components that makes up the application and other information like permission, Application features and the minimum API level this application runs.

android menifest file

Install & Run

Last step is Install and run the application on a device or emulator in order to test and debug it.

That’s end of android application development fundamentals. Net lecture we  will look into more advance features of android platform.

No Responses