1043 views 1 comment

Android 101 : Day 3 | Hybrid Approach

by on July 27, 2015
 

Hello everyone, this is our Fourth tutorial for Android Application Development. In the last tutorial we developed a Simple Toast Application  using XML and Java Approach. Today i will explain all about Hybrid Approach and finally we’ll design a Caller Application in Android using Intent. In our next tutorial we’ll be covering Intent In Android in depth, however today i’ll explain the concept of Intent in brief.

So, What is an Intent ?

An intent is just an abstract description of an operation to be performed. In simple words, Intent is a message passed in Communication between Applications. Intent is nothing but a pre-defined class inside eclipse, that allows you to use various Static Functions defined within it. Take a look at the most used Common Intents in Android.

There are basically 2 important concepts in Intent that we need to know :

  1. Action : It identifies the type of message which has been sent. For example, for a Caller Application we’ll use an action Action_Call.
  2. URI(Universal Resource Identifier) : URI identifies a resource. It is a locator and includes a URI scheme, authority, path, query and fragment by syntax. It is a unique identifier, which identifies the ActionURI for the caller funtion is “tel:“<phonenumber>.

» We will use the setData() method to pass the unique identifier URI.

Permissions

To make use of protected features of the device, we must add the appropriate Permissions. An Application requires permissions in Android when any feature in that application, adversely impacts the user experience or any data on the device.
Our Application includes calling feature that impacts the call charges, therefore we will have to Add a Permission(android.permission.CALL_PHONE) in our Application.

To add Permissions in Android Application follow these Simple Steps :

  • Open AndroidManifest.xml.
  • Go to Permissions tab.
  • Click Add > Uses Permission > Ok.
    Hybrid Appraoch - Using Permissions
  • Select android.permission.CALL_PHONE from Name drop down menu.
    Hybrid Appraoch - Selecting Permissions

Hybrid Approach

In Hybrid Approach, the designing of Layout, Controls & Text is done within XML, whereas Java being the executable file, Event Handling is done within it.

One of the very important concepts of Event Handling is that we have to Interface the Controls designed in XML to Java. To do so, we have to Refer these Controls inside Java.
To refer Controls inside java, all you have to do is remember these 3 steps :

  • Set ID for each Control in Java.
  • findViewById(Id of Control).
  • Typecast the View Control.

Well, this is all you got to know for building a Caller Application in Android. Let’s begin developing our Caller Application.

Caller Application

Following are the steps to Create a Caller Application using Hybrid Approach :

  • Create a New Android Application Project.
  • We’ll start by designing our Application within XML, and then perform Event Handling within Java.

activity_hybrid.xml :

Graphical Layout :

Hybrid Appraoch - Graphical Layout

HybridActivity.java :

AndroidManifest.xml :


Caller Application – Source Code

• Caller Application – Download 


With this we come to an end for our today’s tutorial. Hope you all enjoyed our Fourth Tutorial.
In the next tutorial, we’ll design a Multi-Activity Application using the concepts of Intent in Android. We’ll be back with our Fifth Tutorial in a few days, till then stay tuned!

comments
 
Leave a reply »

 

Leave a Response