Mostrando entradas con la etiqueta Dalvik virtual machine. Mostrar todas las entradas
Mostrando entradas con la etiqueta Dalvik virtual machine. Mostrar todas las entradas

miércoles, 16 de noviembre de 2011

What is Android? and Android Application Architecture


1. What is Android?

1.1. Android Operation System

Android is an operating system based on Linux with a Java programming interface. It provides tools, e.g. a compiler, debugger and a device emulator as well as its own Java Virtual machine (Dalvik Virtual Machine - DVM).
Android is officially guided by the Open Handset Alliance but in reality Google leads the project.
Android supports 2-D and 3-D graphics using the OpenGL libraries and supports data storage in a SQLite database.
Every Android applications runs in its own process and under its own user id which is generated automatically by the Android system during deployment. Therefore the application is isolated from other running applications and a misbehaving application cannot easily harm other Android applications.

1.2. Important Android components

An Android application consists out of the following parts:
  • Activity - represents the presentation layer of an Android application, e.g. a screen which the user sees. An Android application can have several activities and it can be switched between them during runtime of the application.
  • Views - the User interface of an Activities is built with widget classes which inherent fromandroid.view.View. The layout of the views is managed by android.view.ViewGroups. Views often have attributes which can be used to change their appearance and behavior.
  • Services - perform background tasks without providing an UI. They can notify the user via the notification framework in Android.
  • ContentProvider - provides data to applications, via a content provider your application can share data with other applications. Android contains a SQLite DB which can serve as data provider
  • Intents - are asynchronous messages which allow the application to request functionality from other services or activities. An application can call directly a service or activity (explicit intent) or ask the Android system for registered services and applications for an intent (implicit intents). For example the application could ask via an intent for a contact application. Applications register themselves to an intent via an IntentFilter. Intents are a powerful concept as they allow the creation of loosely coupled applications.
  • BroadcastReceiver - receives system messages and implicit intents, can be used to react to changed conditions in the system. An application can register as a BroadcastReceiver for certain events and can be started if such an event occurs.
  • Widgets - interactive components primary used on the Android homescreen to display certain data and to allow the user to have quick access the the information

Other Android components are Live Folders and Android Live Wallpapers. Live Folders display data on the homescreen without launching the corresponding application.

1.3. Dalvik Virtual Machine

Android uses a special virtual machine, e.g. the Dalvik Virtual Machine. Dalvik uses special bytecode. Therefore you cannot run standard Java bytecode on Android. Android provides a tool dx which allows to convert Java Class files into dex (Dalvik Executable) files. Android applications are packed into an .apk (Android Package) file by the program aapt (Android Asset Packaging Tool) To simplify development Google provides the Android Development Tools (ADT) for Eclipse. The ADT performs automatically the conversion from class to dex files and creates the apk during deployment.

1.4. Security and permissions

Android defines certain permissions for certain tasks. For example if the application wants to access the Internet it must define in its configuration file that it would like to use the related permission. During the installation of an Android application the user receives a screen in which he needs to confirm the required permissions of the application.

2. Android Application Architecture

2.1. AndroidManifest.xml

An Android application is described in the file AndroidManifest.xml. This file must declare all activities, services, broadcast receivers and content provider of the application. It must also contain the required permissions for the application. For example if the application requires network access it must be specified here. AndroidManifest.xml can be thought as the deployment descriptor for an Android application.

    
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="de.vogella.android.temperature"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Convert"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="9" />

</manifest> 
   

The package attribute defines the base package for the following Java elements. It also must be unique as the Android Marketplace only allows application for a specfic package once. Therefore a good habit is to use your reverse domain name as a package to avoid collisions with other developers.
android:versionNameand android:versionCode specify the version of your application. versionName is what the user sees and can be any string. versionCode must be an integer and the Android Market uses this to determine if you provided a newer version to trigger the update on devices which have your application installed. You typically start with "1" and increase this value by one if you roll-out a new version of your application.
"activity" defines an activity in this example pointing to the class "de.vogella.android.temperature.Convert". An intent filter is registered for this class which defines that this activity is started once the application starts (action android:name="android.intent.action.MAIN"). The category definition (category android:name="android.intent.category.LAUNCHER" ) defines that this application is added to the application directory on the Android device. The @ values refer to resource files which contain the actual values. This makes it easy to provide different resources, e.g. strings, colors, icons, for different devices and makes it easy to translate applications.
The "uses-sdk" part of the "AndroidManifest.xml" defines the minimal SDK version your application is valid for. This will prevent your application being installed on devices with older SDK versions.

2.2. R.java, Resources and Assets

The directory "gen" in an Android project contains generated values. "R.java" is a generated class which contains references to resources of the "res" folder in the project. These resources are defined in the "res" directory and can be values, menus, layouts, icons or pictures or animations. For example a resource can be an image or an XML file which defines strings.
If you create a new resource, the corresponding reference is automatically created in "R.java". The references are static int values, the Android system provides methods to access the corresponding resource. For example to access a String with the reference id "R.string.yourString" use the method getString(R.string.yourString)); Please do not try to modify "R.java" manually.
While the directory"res" contains structured values which are known to the Android platform the directory "assets" can be used to store any kind of data. In Java you can access this data via the AssetsManager and the method getAssets().

2.3. Reference to resources in XML files

In your XML files, e.g. your layout files you can refer to other resources via the @ sign. For example if you want to refer to a color you defined as resources you can refer to it via @color/your_id or if you have defined a "hello" string as resource you can access it via @string/hello.

2.4. Activities and Layouts

The user interface for Activities is defined via layouts. At runtime, layouts are instances of "android.view.ViewGroups". The layout defines the UI elements, their properties and their arrangement.
UI elements are based on the class "android.view.View". ViewGroup is a subclass of the class "View" and a layout can contain UI components (Views) or other layouts (ViewGroups). You should not nestle ViewGroups too deeply as this has a negativ impact on performance.
A layout can be defined via Java code or via XML. You typically uses Java code to generate the layout if you don't know the content until runtime; for example if your layout depends on content which you read from the internet.
XML based layouts are defined via a resource file in the folder "/res/layout". This file specifies the view groups, views, their relationship and their attributes for a specific layout. If a UI element needs to be accessed via Java code you have to give the UI element an unique id via the "android:id" attribute. To assign a new id to an UI element use "@+id/yourvalue". By conversion this will create and assign a new id "yourvalue" to the corresponding UI element. In your Java code you can later access these UI elements via the method findViewById(R.id.yourvalue).
Defining layouts via XML is usually the preferred way as this separates the programming logic from the layout definition. It also allows the definition of different layouts for different devices. You can also mix both approaches.

2.5. Activities and Lifecycle

The operating system controls the life cycle of your application. At any time the Android system may stop or destroy your application, e.g. because of an incoming call. The Android system defines a life cycle for activities via pre-defined methods. The most important methods are:
  • onSaveInstanceState() - called if the activity is stopped. Used to save data so that the activity can restore its states if re-started
  • onPause() - always called if the Activity ends, can be used to release ressource or save data
  • onResume() - called if the Activity is re-started, can be used to initiaze fields

The activity will also be restarted if a so called "configuration change" happens. A configuration change for example happens if the user changes the orientation of the device (vertical or horizontal). The activity is in this case restarted to enable the Android platform to load different resources for these configuration, e.g. layouts for vertical or horizontal mode. In the emulator you can simulate the change of the orientation via CNTR+F11.
You can avoid a restart of your application for certain configuration changes via the configChanges attribute on your activity definition in your AndroidManifest.xml. The following activity will not be restarted in case of orientation changes or position of the physical keyboard (hidden / visible).

    
<activity android:name=".ProgressTestActivity"
     android:label="@string/app_name"
     android:configChanges="orientation|keyboardHidden|keyboard">
</activity>
   

2.6. Context

The class android.content.Context provides the connections to the Android system. It is the interface to global information about the application environment. Context also provides access to Android services, e.g. the Location Service . As Activities and Services extend the class "Context" you can directly access the context via "this".

viernes, 21 de octubre de 2011

Android 4.0 Ice Cream Sandwich: everything you need to know


Android 4.0 Ice Cream Sandwich is now official.
Here's what you need to know about the latest version of Google's mobile OS which combines the best of the Android 2.x phone interface with the Android 3.x Honeycomb tablet interface.
Ice Cream Sandwich is designed for use with both phones and tablets.

Android 4.0 Ice Cream Sandwich features

Android ICS offers a massive array of improvements over its predecessors bringing the best of both Gingerbread and Honeycomb while providing a raft of new innovations.
The company says 4.0 is a complete rethink of Android's image and is part of a push to make the OS "Enchant me, Simplify My Life, and Make Me Awesome."
Android 4.0 ice cream sandwich
"Android 4.0 builds on the things people love most about Android," says Google in a post on the Android Developers Blog. "Easy multitasking, rich notifications, customizable home screens, resizable widgets, and deep interactivity — and adds powerful new ways of communicating and sharing."
Android 4.0 ice cream sandwich
Minor improvements include better copy and paste, data logging and warnings and, at last, the opportunity to easily grab screenshots by holding down the power and the volume buttons.
The keyboard and dictionaries have also been revamped, says Google. "Error correction and word suggestion are improved through a new set of default dictionaries and more accurate heuristics for handling cases such as double-typed characters, skipped letters, and omitted spaces. Word suggestion is also improved and the suggestion strip is simplified to show only three words at a time."
"To fix misspelled words more easily, Android 4.0 adds a spell-checker that locates and underlines errors and suggests replacement words. With one tap, users can choose from multiple spelling suggestions, delete a word, or add it to the dictionary."
Android 4.0 ice cream sandwich
The new OS is designed to bring common actions to the fore, with better animations and an entirely new typeface - more on that shortly.

Android 4.0 Ice Cream Sandwich Galaxy Nexus

Google kicked off its launch event by announcing the Samsung Galaxy Nexus, which will be the first device to run Ice Cream Sandwich and will be launched in November. Check out Samsung Galaxy Nexus: what you need to know.
Galaxy nexus

Android 4.0 Ice Cream Sandwich update

Google has confirmed it is working on an Android 4.0 update for the Samsung Nexus S and other Android devices.
Director of Android operating system User Experience Matias Duarte told Engadget that Google is. "Currently in the process for releasing Ice Cream Sandwich for Nexus S. Theoretically it should work for any 2.3 device."
Motorola confirmed to TechRadar that the Motorola Razr will launch in the UK with Android 2.3, but that there will be an update to 4.0in 2012.

Android 4.0 Ice Cream Sandwich Roboto

Among the first new features championed by Google at the Hong Kong media event was a brand new typeface for Android in the shape of the easy-to-read "Roboto."

Android 4.0 Ice Cream Sandwich System Bar and Action Bar

At the launch event, Google showcased a host of virtual buttons that appear at the bottom of the screen in some apps and allow users access to areas of the device like phone and contacts.
These are located in the System Bar - present in all apps - and enables you to navigate instantly to Back, Home, and Recent Apps. Virtual buttons are present across all apps, but can be dimmed by applications for full-screen viewing.
You can also access the contextual options for each app in the Action Bar at the top of the screen.

Android 4.0 Ice Cream Sandwich voice control

Android 4.0 introduces new voice input engine, You can dictate the text you want, for as long as you want. After dictating, you can tap the underlined words to replace them from a list of suggestions.

Android 4.0 Ice Cream Sandwich multitasking

Multi-tasking has also been given a boost and with ICS it's easier to see which apps you've been using recently. If you decide you're done with using one, you can easily flick it away to close.
Google says it has made multitasking "even easier and more visual" on Android 4.0. The Recent Apps button lets users jump instantly from one task to another using the list in the System Bar. The list pops up to show thumbnail images of apps used recently — tapping a thumbnail switches to the app.
Android 4.0 ice cream sandwich

Android 4.0 Ice Cream Face Unlock

Perhaps the most 'Star Trek' of all the new Android 4.0 features is a new piece of functionality called Face Unlock which, as the name suggests, unlocks your handset based on facial recognition tech.
Android 4.0 ice cream sandwich
You can also do more without unlocking. As in iOS 5 you can jump straight to the camera. You can also pull down the notifications window.

Android 4.0 Ice Cream Sandwich Home Screen folders

Like iOS before it, Android is now getting home screen folders too. You can group apps or shortcuts together and, as with iOS, you can do this just by dragging icons on top of one another.From the All Apps launcher, you can now drag an app to get information about it or uninstall it should you wish.
Android 4.0 ice cream sandwich

Android 4.0 Ice Cream Sandwich notifications

Notifications have also been improved. On larger devices - tablets - the updates appear in the System Bar, while on phones the notifications roll down from the top of the screen as before.
Android 4.0 ice cream sandwich

Android 4.0 Ice Cream Sandwich favorites tray

On phones and other "smaller screen devices" (that's Google speak), there's now a customisable favorites tray. You can put anything you want here - apps, folders, shortcuts - whatever you want - check out this screen:
Widgets

Android 4.0 Ice Cream Sandwich widgets

As in Honeycomb, you can now resize widgets on phones too. As in that OS, the widgets in 4.0 are designed to be far more interactive, enabling you to flick through appointments, play music and more.

Android 4.0 Ice Cream Sandwich data

Android 4.0 includes new graphical displays so you can see how much data you're using and how much you've used over Wi-Fi or cellular. You can also see the amount of data used by each running application.
Warning levels can also be specified, as well as determining how much background data apps can use.
Android 4.0
Android 4.0

Android 4.0 Ice Cream Sandwich camera

Android 4.0 Ice Cream Sandwich also brings some much-needed improvements to Google's camera UI, which the company says it has been working on with Samsung.
ICS devices, and the newly announced Samsung Galaxy Nexus in particular, will have 1080p video, zero shutter lag, a new picture-stitching panorama mode, easier sharing and Instagram-esque filters.
In the panorama mode, you can start taking the picture and then move the camera. The phone assembles the full range of continuous imagery into a single panoramic photo.
Android 4.0 ice cream sandwich
"When taking pictures, continuous focus, zero shutter lag exposure, and decreased shot-to-shot speed help capture clear, precise images," says Google. "Stabilized image zoom lets users compose photos and video in the way they want, including while video is recording. For new flexibility and convenience while shooting video, users can now take snapshots at full video resolution just by tapping the screen as video continues to record."
There's also built-in face detection as well as tap to focus.
Android 4.0 ice cream sandwich
There are also various editing tools included, too, while there's sharing via Google+, message, Bluetooth, email or Picasa upload.
Android 4.0 ice cream sandwich
There's also an improved gallery widget, as well as new album layout with larger thumbnails.
Thankfully you can also now take screenshots - this is going to make our job a whole lot easier!
For video, there's also Live Effects you can apply to distort faces or alter backgrounds.

Android 4.0 Ice Cream Sandwich apps

The People app does what many manufacturers have been doing on Android for ages - bringing together various social networking feeds into one place,
This offers richer profile information, including a large profile picture, phone numbers, addresses and accounts, status updates, and a new button for connecting on integrated social networks.
The Calendar app has also been updated to bring together different calendars, while the email app can now autocomplete responses and is able to store oft-used replies.
Android 4.0 now also supports visual voicemail.
The web browser is also improved - especially in terms of speed - and now allows up to 16 windows. You can now sync it with Google Chrome and the browser supports offline browsing - it can save versions of web pages you choose.
Android 4.0
There's also a new NFC-based app called Android Bump, which allows two phones to exchange a wealth of information, just by holding them together.
It can be used to share websites, maps and start games.
Here's a video of the Android 4.0 launch event if you have the time - it's an hour long!



Best Regards and Happy Friday for all !


Lic. Mariano Salvetti

lunes, 18 de abril de 2011

--- Android Features ---

We have presented an introduction to the Android OS, and born of the hands of Google and how we can develop applications.

Now review the features of the platform, then set up our development environment so that, through an emulator, and thanks to the Eclipse IDE we have a production environment that allows us to develop applications that run on mobile devices (smartphones and tablets) and we can test without having the device.
ANDROID PLATFORM FEATURES
Let us briefly review the main features Android OS, which will introduce later in this blog and go interiorizing to dominate as programmers:


Application Framework: allows replacement and reuse of components.

Integrated browser: openSource based on Webkit engine, we already have a browser, ie, our applications can display HTML, something very interesting.

SQlite: A database for structured data, which integrates directly with the applications and we can use in our programs.

Multimedia: Support common media formats, audio, video and image plane (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF).

Dalvik Virtual Machine: A virtual machine application. We allow each application to run in a separate process with its own virtual machine instance.

Camera, GPS, compass, accelerometer. GSM Telephony, Bluetooth, EDGE, 3G and wireless cell dependent on which you run Android.

Touch Screen: SmartPhones models already exist, such as Kyocera Echo, with Android and double touch screen.

Android Market: allows developers to make applications, free or paid, in the market through this application accessible from all phones with Android.

Yes, there is a relationship between the Java Programming Language, the Android platform and the Dalvik virtual machine.

The programmer writes one (or more) classes in Java, then compile and get a file (. Class) to Java bytecode.

On the other side of the relationship, the Android SDK has a utility called "DEX", which is responsible for converting a file. Class in a file. Dex, so what is a. Dex?

Well, one. Dex has the bytecode. Class "translated" so that they understand now the Dalvik virtual machine. Then, this. Dex (or more) is packaged with other resources of the application form the project developer, in a file. Apk, which is the executable Android.

Dalvik virtual machine IS NOT A Java virtual machine, often it is confused, but we have to clarify this from the start, since you are working with bytecode is Java bytecode.

This virtual machine is optimized for low memory use and allows us to run multiple instances by delegating to the underlying operating system support for process isolation, memory management and thread.

According to official documentation has the Android site, the name for this virtual machine was chosen in honor Dalvík Bornstein, a town of Eyjafjörður, Iceland, where his ancestors lived.

With this we have a brief glimpse of what is Android, which supports it, and if we are programmers is time to start the installation process of the tools for programming.

We see in the next innings, best regards,

Mr. Mariano Salvetti