Using startActivity vs startActivityForResult

The most common way to invoke an Activity is by using the startActivity method, but there is also another method you will see used in specific instances startActivityForResult . Both pass control to a different Activity. The difference with regard to startActivityforResult is that it returns a value to the current Activity when the Activity being invoked is complete. It in effect allows you to chain activities and expect callback-style responses you get the response by implementing the...

Interacting with the phone

In your day-to-day development you will often want to interact with the phone. This interaction may be as simple as dialing outbound calls through built-in intents, or it may involve intercepting calls to modify them in some way. In this section we are going to cover these basic tasks, and we will examine some of the phone number utilities Android provides for you out of the box. One of the more common things you will do with the Android telephony support doesn't involve the telephony APIs...

Using LocationManager and LocationProvider

When building location-aware applications on the Android platform, there are several key classes you will use very often. A LocationProvider provides location data using several metrics, and its data is accessed through a LocationManager. LocationManager, along with returning the available providers, also allows you to attach a LocationListener to be updated when the device location changes and or directly fire an Intent based on the proximity to a specified latitude and longitude. The...

return trueIntent extra C

intent new Intent this, ReviewCriteria.class startActivity intent return true return super.onMenuItemSelected featureld, item protected void onListItemClick ListView l, View v, D int position, long id lt 1-' RestaurantFinderApplication application RestaurantFinderApplication getApplication Intent intent new Intent Constants . INTENT_ACTION_VIEW_DETAIL getIntent .getIntExtra Constants . STARTFROM_EXTRA, 1 lt 1 startActivity intent Pass startFrom Get Application extra value object and set private...

Accessing telephony information

Android provides a very informative manager class that supplies information about many telephony-related details on the device. Using this class, TelephonyManager, you can access many of the GSM SIM properties we have already discussed, and you can obtain phone network state information and updates. Attaching an event listener to the phone, in the form of a PhoneStateListener, which is done via the manager, is how you can make your applications aware of when phone service is and is not...

Drawing graphics in Android

In this section we are going to be looking at Android's graphical capabilities as well as examples of how to make simple 2D shapes. We will be making use of the android.graphics package see android graphics package-summary.html , which provides all the low-level classes and tooling needed to create graphics. The graphics package supports such things as bitmaps which hold pixels , canvas what your draw calls draw on , primitives such as rectangles or text , and paint which you use to add color...

Working with maps

We have demonstrated the start of the MapViewActivity our Wind and Waves application will use in the previous sections. There we covered the supporting classes and the handling of registering to receive location updates. With that structure in place, we now will focus on the map details themselves. The MapViewActivity screen will look like the screen shot in figure 11.6, where several map Overlay classes are used on top of a MapView within a MapActivity. In order to use the com.google....

Understanding layout

One of the most significant aspects of creating your UI and designing your screens is understanding layout. In Android, screen layout is defined in terms of ViewGroup and LayoutParams objects. ViewGroup is a View that contains other views has children and also defines and provides access to the layout. On every screen all the views are placed in a hierarchical tree, so every element has children, and somewhere at the root is a ViewGroup. All the views on the screen support a host of attributes...