Real information about Kansas Extended Auto Warranty at Auto Car Warranty
Kansas Extended Auto Warranty

Kansas Extended Auto Warranty

Introduction to Android

for mobile programming

This an introduction to the Android Mobile OS platform.

Android's Humble Beginnings

Android, the mobile OS platform, ideas were formed by a startup formed by some employees from danger, WebTv, and T-mobile. The general idea was that there would be an XML-lized UI with every application including OS ones being customize-able and extendable. Google bought Android Inc in 2005 to pursue an Open Mobile Platform OS strategy with Java applicatiosn at its core.

The Android OS Mobile Platform is considered visually a UI modal system. That means that a user is required to interact with the child window before being returned to the parent window. Most mobile OS platforms systems are designed in this manner to deal with small screen space constraints.

Technology From Other Places

As so often the case in mobiel technology technology was borrowed from other places. First lets talk about the interprocess communication(IPC). The Android OS is a non-RTOS OS based on a LInux Kernel, specifically the distro is known as MontaVista.

That OS communicatiosn with the baseband RTOS(baseband is the radio/modem and etc) to complete the telephone calls. Because the OS apps are non RTOS they have to communicate states and etc to other OS process and this is where IPC comes in the picture. Its a Palm invention as applied to mobile operating systems.

The second technology borrowed is from the Apache Harmony Project which is an open source java stack incluiding the classes found in a normal desktop jdk and the VM machinery found in a JRE. while the VM was replaced by a register Vm to perorm better in a mobile environment, most of JavaSE classes were kept and thus Android Java is closer to JavaSe than JavaME CDC.

Tghe third technology borrowed is form Java Swing itself, in that a data/view relationsh0p is maintined in the interactiosn between the UI and data layers. The whole Android Application Model is often referred to as a compoenent based application model and rest of the compoenets wil be introduced in the next section.


Application Model and Java Model

The Android Application and Java Model is different than both JavaME and JavaSE. First. to fully understand the Android Application Model lets start form the basic differences.

An Android applicaion has its onw userID, its own separate Linux process and it sown instance of the VM. As a comparison until recently JavaME VMs did not have this feaure and J2ME applications were loaded each into the same VM on a mobile handset.

Since each Android Applicaitona and the OS applications run in their own VM instance we need a way to communicaiton among these applications. Those features are proved by 3 components, Content Providers, Services, and Broadcast Receivers.

You can think of the main Activities Visual Interface Android Component as the visual UI fro al lthese components working together in an Andorid Application.

The Intent Glue MagicThe main Andorid components, activities, services, and broadcast receivers are activated by asynchronous messaging called intents that uses the underlying OS IPC bus. Except for Content Providers/Conent Resolvers which can be from Application to another Application generally intents are messaging among component in one Android Application.

Development Tools

The preferred set fo tools is the Android SDK and the Eclipse Android Development Tool(ADT) plugin. It is nto that you cannot use a different IDE, its just nto as integrated as Eclipse is but I wil still show you how to acess the command line tools when possiblo eot mke upfor the lack of Andorid integration in your IDE tool.

Android SDK
The Android SDK can be downloaded from:

http://developer.android.com/sdk/1.5_r2/index.html

Instal the SDK folder in your home directory with no spaces in the folder name. For those on windows ensure that your java jdk instal has no spaces in the folder name and is nto installed in the documents foldeer but ina nice place say at root of main drive.

Now, we need to set-up ANDROID HOME path to point to the tools sub-folder of your SDK install for your OS to recognize when you give command lien commmands for those tools. ON linux and Mac and Solaris you are looking for the bash dot file in your home directory to edit to put that path in. On windows you need to be in System Enviornment properties to enter the varaible name and its path.

Code/Error Completion

Every modern IDE has a code competion feature enabled by having java sources locatable somewhere within a SDK. So where is Android Java sources? Androdi is a relativeley new project an thus ther ei snot a automatic set up of packaging java sources with the SDK to enable code completion. at a later part of this series I will show how to downl;aod coe so tha tyou can get coe completion enabled but for right now we will cheat a bit.

Someone has taken the time ot gather sources to the cupcake branch which is close enough to the 1.5r2 SDK release to be suable as our Andorid java sources to enable code completion:
http://www.digginmobile.com/android.asp
Once, you click on the link to download and get the downlaod you will unzip in Your-SDK-Install/platfomrs/android-1.5/sources so that you can point your IDE ot it to enable code/error completion. Thus whe you run an Android application in the Eclipse debugger you will get error reports reporting the exact line number of the error in Andoird source an dti wil how you the Android source.


Eclipse IDE


Eclipse itself can be downloaded from:

http://www.eclipse.org/downloads/

Those of you who will choose to do advance stuff as stack traces and memory dumps you will want to choose the Eclipse Modeling Tools version as it includes both Eclipse MAT an dEclispe TPTP which are required to complete those tasks.

Eclipse ADT Plugin

Once the Eclipse IDE is installed, you can install the Eclipse ADT plugin by using the Eclipse Manager Update URL from this page:

http://d.android.com/sdk/1.5_r2/installing.html#installingplugin

Once you have the plugin installed adn the IDE restarted go to windows>preferences>android and enter the path to your SDK like:

You only need to add th epath to the SDK as the plugin wiil take care of finding the tools sub-folder. Now for magic, go to windows>avd manager:
Put in a name for your AVD, choose the 1.4 SDK target, and specify a SDCard size of say 1644M and choose a skin and than press the Create AVD button. Yiu computer wil take a minute to create the SDCard image so grab some coffee.

You are now ready to develop a real Android Appication. No pretend HelloWord here, lets make a real Android application as that will enalbe you to focus on the componentsof Android Applciations and along the way I can show some standard practiecs that will keep you out programmig trouble..

Parts of a Sample Application

Thus, you are probalbly wondering what we are going to build. while the HomeApplication that you see when you first bootup:
might seem too complicated for an introducitonot Android. However, I can break it down into several tutorials and remove some features so that we have some nice steps into a full introduction to Android. The sample application is called HomeZ.

HomeZ Beginning Structure

Now its time for us to create our project. In Eclipse you wil go to File>New>Other and on the resulting screen scroll down until you see andorid and expand that list and click on Android New Project. You will enter your project name, choose a SDK version, enter the project package name, and enter the ActivityName and press create project/finish.

The plugin will automatically create the project for you and the main Activity java class. Lets start with the java bolierplate code the plugin creates for us:

package com.mobilebytes.homeztutorial1;
import android.app.Activity;
import android.os.Bundle;


public class HomeZActivityTutorial1 extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);
}
}

The Android Application lifecyle starts wih creating the Activity. But how do we know if the Activity is created when we attempt to overrride the onCreate method to our super class Activity? If you remove the line super.onCreate() you get an answer as the Applicaitn wil not start. Bascially the super.onCreate() casues he onCreate method in our super class to be called befor eour overrridign the onCreate method thus ensuring that the application will start correctly after the onCreate method in the super clas sis actually somewhat constructed.

onCreate(Bundle savedInstanceState) creates our first instance of what is known in the Android world as a Parcelable. What is a Parcelable?

A parceleable is our first instance of IPC in action. A parceleabler is a container in which object primitive data can be stored in which a Android Dalvik class loader can than restore the class with that data. In this case a Bundle parceleable is special parceleable thay allows the sotreage of key/value pairs. Later, we will learn about the other forms of parceleables that form the Android light RPC framework of communication.

For right now, just rember our overrride is initalizing a special parceleable container called a Bundle so that we can store key value pairs representing application state data.

The VIEW

In Android's case they take the swing concept of data and views and extend it so tha the UIis xml-lized. Let us get to know the UI of Android. Every UI in Android can be xml-lized and store as an xml document in the res folder of an application.

setContentView(R.layout.main);

that command is setting the contentView of the Android Application to what is contained in the main.xml file in the res/layout sub-folder. We know its a XMl file in the res sub-folder due to it not having the prefix andorid.R. Right now it has a Linear Layout UI container and a textview element as evidenced by the main.xml file in the res//layout sub-folder:





You wil aleays have at least one layout container for an Android Application. An Android Layout contianer can contain many UI view widgets which textiew is just one of them. THe layoiut container will always have a namespace declaration in thi scase the Android Resource namespace declaration.

The objects within the resources xml files can be referenced by a @res-type/res-boject-name syntax. In this case the res/values/strings.xml file has a hello string that is used here. Notice that the symtax is different than the syntax used in setContentView(R.layout.main).

If you are using eclipse you can open the res/layout/main.xml file as Andoid Layout manager editor view and se this:
As you can see not lonly do you have an edor to visually arrange Ui items you can see a static result as well. Later, I wil show you both methods of edting the main.xml file visually in Eclipse and by hand to design the UI elements of HomeZ, our sample HomeScreen Application.

Whne you create an Android Project through either the Eclipse ADT plugin or through the use of the Android SDK command line tools, that act creates some default items such as ares/layout/main.xml fiel with a linear layour container and a textiew, an AndoridMainfest.xml and a res/values/strings.xml file:



Hello World, HomeZActivityTutorial1!
HomeZTutorial1


Notice in the main.xml visual layout view that the String Value 'hello' is displayed in its textview widget in the LinearLayout contianer. What pulls these wdigest and layout containers and activityes tother into an Android Applications is an Android Mainifest XML file and we will in the next section be introduced to the AndroidManifest.

Application Manifest

Let us look at the non visual form of the file first:












Whenever you create a porject using the IDE plugins or SDK tools you will get something similar. Npotice right at the top we have the Andorid Resource namespace declaration and than the package name of the applicatin and a versionsCode number and versionName.

Notice that to use res folder objects its the "@resource-type/object-name" syntax. The activity name gets a dot prefix to denote root. Intent-filters set-up the intents the appplication will use for inter-application communication among different activities withn the same application.


sets up the main entry point of the appication and

will tell the Android application Launcher that this application should be in its lsit of applications that are launchable.

SDK version is denoted by:

and has been a requirement since SDK 1.1 with 3 representing 1.5 and 2 representing SDK 1.1. It is not a release number but an API level number.

Part fo the reason to teach and develop tutorials is to pass on all the tricks and secrets so that your development time for each Android Application is less in time measurement and more enjoyable. Unlike other rmobile platforms we can Mock test obejcts with Android and thus lets introduce you to unit and mock testing with Android.


Unit and Mock Testing

First, a little Andorid Java VM background. The Andoird VM, Dalvik, is a register based Virtual Machine that executes java in a bytecode format called dalvik bytecode. for both unit testing and code coverage and etc that measn that the normal machinery to instrurment classes that most Mock Object Frameorks and Code Coeverage Frameworks uses cannot be used with Android as the underlying bytecode mnipulatin frameworks in use do nto understand dalvik bytecode.

Thus, the Andorid Project came up with their own Junit version to use, Junit3, and create a set of Mock Objects and a small Mock object Framework for unit testing. Because Junit and its runner framewor k s already included in the Android.jar you are including the Junit jar in an ext libs folder sothat the java compiler can pick it upas a refernce during compiling.

A common miss-conception among un-informed blogs is to enable Unit testing by removing the Android.jar from the classpath IDE container and adding the junit.jar. DO NOT DO THAT! Unit and Mock object testing in Android Application Development was designed to be run in the emulator and on the deivce.

The best way to get into the unit and mock test habit is to start at the beginning of a project. Using best development standards we create a separate sub-folder called test and the project root which contains a sub-folder called src.

Now lets mock that HomeZActivity class. First, in your IDE you need ot register that 2nd src sub-fodler with yoru IDE builders so that things get created right in that folder. In Elcips eits right-click on project and properties, than java build path to get:
add the tests/src folder and click the okay button. Now we are ready to create our first mock class. At this point since our Android Applications into fully created we wil only have two clases the Mock class to mock the Activty and the AllTests class.

You mock class wil look like this:
package com.mobilebytes.homeztutorial1.tests;

import com.mobilebytes.homeztutorial1.HomeZActivityTutorial1;

import android.content.Intent;
import android.test.ActivityUnitTestCase;
import android.test.suitebuilder.annotation.MediumTest;

/*
* we are completely doing an isolation unit test of the activity class
* This testing the activity outside the system and thus cannot
* launch another activity.
*
*/
public class HomeZActivityTutorial1Test extends ActivityUnitTestCase{

private Intent mStartIntent;

public HomeZActivityTutorial1Test(
Class HomeZActivityTutorial1) {
super(HomeZActivityTutorial1.class);
// TODO Auto-generated constructor stub
}

@Override
protected void setUp() throws Exception {
// TODO Auto-generated method stub
super.setUp();

mStartIntent = new Intent(Intent.ACTION_MAIN);
}

/**
* The name 'test preconditions' is a convention to signal that if this
* the test case was not set up properly and it might
* explain any and all failures in other tests if it fails.
* Do not assume that is run before other tests
*/
@MediumTest
public void testPreconditions() {
startActivity(mStartIntent, null, null);

assertNotNull(getActivity());

}



@MediumTest
public void testLifeCycleCreate() {
HomeZActivityTutorial1 activity = startActivity(mStartIntent, null, null);

// onCreate() has been called, but nothing else
// Complete the startup of the activity
getInstrumentation().callActivityOnStart(activity);
getInstrumentation().callActivityOnResume(activity);


// We can test for various configuration aspects, or we could
// use a Mock Context to confirm that everything is setup properly
getInstrumentation().callActivityOnPause(activity);


// At this point you could confirm that the activity has paused properly, as if it is
// no longer the topmost activity on screen.
getInstrumentation().callActivityOnStop(activity);
// Becuase ActivityUnitTestCase.tearDown(), which is always automatically called, will take care
// of calling onDestroy() we should at some point test to confirm that
// resources have been released

}



}

At this point we are only concenred to see if the Application has been created and to test certain lifecycle events o fthe application and to ensure that the activity can launch. The AllTests class than looks like this:
package com.mobilebytes.homeztutorial1.tests;

import android.test.suitebuilder.TestSuiteBuilder;
import junit.framework.Test;
import junit.framework.TestSuite;

/**
* A test suite containing all tests for HomeZTutorial1.
*
* To run all suites found in this apk:
* $ adb shell am instrument -w \
* com.mobilebytes.homeztutorial1.tests/android.test.InstrumentationTestRunner
*
* To run just this suite from the command line:
* $ adb shell am instrument -w \
* -e class com.mobilebytes.homeztutorial1.tests.AllTests \
* com.mobilebytes.homeztutorial1.tests/android.test.InstrumentationTestRunner
*/
public class AllTests extends TestSuite {

public static Test suite() {
return new TestSuiteBuilder(AllTests.class)
.includeAllPackagesUnderHere()
.build();
}
}

in the tests sub-folder you will create an AndroidManifest.xml file that has this:





Next page: Cadillac Extended Warranty


Bookmark/Share This Page:


Bookmark and Share


Kansas Extended Auto Warranty News




Introducing the Government-Backed DMV Automotive Repair Center! (Best choice)...

21 Apr 2011 at 1:43am  Introducing the Government-Backed DMV Automotive Repair Center Best choice tags: automakers_bailoutauto_warrantychryslerdetroitdmvEntertainmentgeneral_motorsIntroducing the Government-Backed DMV Automotive Repair Center! (Best choice) video
FunnyHumorClips

Read more...




Elite Auto Warranty

3 Nov 2010 at 8:33pm  Get your warranty for your car Don't forget to share with me in my blog tags: car_insurancecar_quotesauto_warrantyTechnologyElite Auto Warranty


Read more...


Shop RadarBusters.com Today!


Amazon Kindle
Kindle: Amazon's New Wireless Reading Device