Saturday, December 19, 2009
Thursday, November 26, 2009
Wednesday, July 01, 2009
Wednesday, June 03, 2009
SQLite Cursors and Content Values:
Queries in Android are returned as Cursor objects. Rather than extracting and returning a copy of the result values, Cursors act as pointers to a subset of the underlying data. Cursors are a managed way of controlling your position (row) in the result set of a database query.
The Cursor class includes several functions to navigate query results including, but not limited to, the following:
moveToFirst >> Moves the cursor to the fi rst row in the query result.
moveToNext >> Moves the cursor to the next row.
moveToPrevious >> Moves the cursor to the previous row.
getCount >> Returns the number of rows in the result set.
ing an exception if no column exists with that name).
getColumnName >> Returns the name of the specifi ed column index.
Monday, May 04, 2009
SQLite Database for Data Storage and Retrieval :
Rapid and efficient data storage and retrieval are essential for a device whose storage capacity is limited by its compact nature.
Android provides a lightweight relational database for each application using SQLite.
By default, each application database is sandboxed — its content is available only to the application that created it — but Content Providers supply a mechanism for the managed sharing of these application databases.
Native Google Maps, Geocoding, and Location-Based Services :
Native map support lets you create a range of map-based applications that leverage the mobility of Android devices. Android lets you create activities that include interactive Google Maps as part of your user interface with full access to maps that you can control programmatically and annotate using Android’s rich graphics library.
Android’s location-based services manage technologies like GPS and Google’s GSM cell-based location technology to determine the device’s current position. These services enforce an abstraction from spe-cifi c location-detecting technology and let you specify minimum requirements (e.g., accuracy or cost) rather than choosing a particular technology.
It also means that your location-based applications will work no matter what technology the host handset supports. To combine maps with locations, Android includes an API for forward and reverse geocoding that lets you fi nd map coordinates for an address, and the address of a map position.
Thursday, April 23, 2009
Access to Hardware including Camera, GPS, and Accelerometer :
Android includes API libraries to simplify development involving the device hardware. These ensure that you don’t need to create specifi c implementations of your software for different devices, so you can create Android applications that work as expected on any device that supports the Android software stack.
The Android SDK includes APIs for location-based hardware (such as GPS), camera, network connec-tions, Wi-Fi, Bluetooth, accelerometers, touch screen, and power management.
Native Android Applications :
Android phones will normally come with a suite of preinstalled applications including, but not limited to:
- An e-mail client compatible with Gmail but not limited to it.
- An SMS management application.
- A full PIM (personal information management) suite including a calendar and contacts list, both tightly integrated with Google’s online services.
- A fully featured mobile Google Maps application including StreetView, business finder, driving directions, satellite view, and traffi conditions.
- A WebKit-based web browser.
- An Instant Messaging Client.
- A music player and picture viewer.
- The Android Marketplace client for downloading thied-party Android applications.
- The Amazon MP3 store client for purchasing DRM free music.
All the native applications are written in Java using the Android SDK and are run on Dalvik.
The data stored and used by the native applications — like contact details — are also available to third-party applications. Similarly, your applications can handle events such as an incoming call or a new SMS message.
The exact makeup of the applications available on new Android phones is likely to vary based on the hardware manufacturer and/or the phone carrier or distributor.
Wednesday, April 01, 2009
More XML Layouts :
RelativeLayout :
Each child element is laid out in relation to other child elements.
Relationships can be established so that children will start themselves where a previous child ends. Children can relate only to elements that are listed before them. So, build your dependency from the beginning of the XML file to the end.
AbsoluteLayout :
Each child must be given a specific location within the bounds of the parent layout object. The AbsoluteLayout object is probably the easiest to build and visualize but the hardest to migrate to a new device or screen size.
TableLayout :
TableLayout is a layout object that allows you to specify table rows.
Android tries to arrange each of the child elements into the correct row and columns.
Sunday, March 01, 2009
Easy and Fast, the XML Layout :
XML layouts might seem simple at first, but it’s going to get complicated really quickly.
Laying Out :
Most XML screens will be wrapped in a layout object. Layout objects come in many different flavors.
LinearLayout :
All elements are arranged in a descending column from top to bottom or left to right.
Each element can have gravity and weight properties that denote how they dynamically
grow and shrink to fill space. Elements arrange themselves in a row or column notation
based on the android:orientation parameter.
Wednesday, January 28, 2009
Creating an XML Layout File :
Now that you have an image resource, you can add it to your XML layout file.
These files are kept in res/layout/, and you should currently have one called main.xml.
Add a new XML file called splash.xml, and copy the contents of the main.xml file into it.
Next, modify the file by removing the
looks like the following:
android:layout_width="fill_parent"
Using Android’s XML layout objects is simple and straightforward.
As I mentioned, files in the /res directories can be referenced with the @ symbol
as shown earlier, for example, android:src="@drawable/menu_background".
Further, layout_width and layout_height dictate the size of the image view.
Look to make sure your new layout file has been added to R.java.
It should appear as follows:
public static final int splash=0x7f030001;
Adding the Image Resource :
First you’ll need a sample splash screen image. The “socially awkward” splash screen I’ve included is not going to win any awards, but it is a good poke at the rash of social networking applications that seem to keep cropping up in the mobile space right now.
To add this new resource, I’ve placed menu_background.jpg inside res/drawable.
Make sure a new ID is added to R.java.
It should look something like this:
public static final int menu_background=0x7f020001;
This is now your means of loading and drawing the image from within your code.
You’ll return to this concept in the next chapter on user interaction.
Android Functionality :
Just like the midlet, an activity uses a series of functions to interact with the outside world.
At its base, your activity must override the method onCreate. Other functions you’ll want to override are onStop, onPause, onResume, and onKeyDown. These few functions are what will let you tie your activity into the Android handset at large.
Thursday, January 01, 2009
Android vs. Java ME vs. BREW :
A BREW application will, in the vast majority of all cases, consist of a single applet.
That applet communicates with the rest of the handset through receiving and sending events. You can think of a Java ME application, on the other hand, as an extension of the Midlet class.
The midlet has functions for starting, stopping, pausing, key handling, and performing any other interaction between the handset and application.
A Java ME application usually consists of a single midlet.
Android applications can have any number of activities registered with the
handset through the AndroidManifest.xml file. Android’s multiactivity
architecture is probably the major difference between developing for Android and developing for other handset SDKs.
This single fact makes it much easier to write modular, compartmentalized code. In BREW and Java ME, a developer will implement most functionality within the confines of the midlet or the applet. In Android, you can write an activity, content handler, intent receiver, or service to handle nearly anything.
Once you’ve written an activity to edit a text file, you can refer to this activity in all future applications you write by sending and receiving intent actions.
This isn’t to say that such architecture isn’t possible within BREW or Java ME.
It just has to be done at the Java, C, or C++ level or, in Brew, with cumbersome extensions instead of being built smoothly into the application
framework.