Using DDMS to update location

We talked a lot about DDMS the Dalvik Debug Monitor Service in Chapter 5, but two features are related to location updates. The Emulator Control pane of the DDMS screen provides several ways of controlling the running emulator. After switching to the DDMS perspective click on DDMS in the upper right of the Eclipse window , you should see the Emulator Control pane in the middle left of the DDMS window Figure 9-1 . You will probably have to scroll down in that pane to see the controls related to...

Intents Simple LowOverhead IPC

The Android system uses Intent objects to enable applications to specify an Activity or Service. Intent objects also deliver data from one application to another, providing a simple and convenient form of IPC. The Intent class, the Activity class, and Android's Intent-based inter-process communication solve one of the user interface problems of smartphone platforms that support multiple separate applications they feel like a collection of separate programs. You don't have the simplicity of...

MapView and MyLocationOverlay Initialization

At startup, and when we select Current Location from the Spinner, we want to display a map of our current location, and we want that map to track us as we move around. For this map we will use the MyLocationOverlay class. When we select a specific location from the Spinner, we want to display a map of that location, turn off location updates, and not track movement. Let's look again at the code in MicroJobs.java that initializes the MapView and the MyLocationOverlay that tracks our current...

Getting a Signing Certificate While Debugging

When you're creating and debugging your application that uses a MapView, or when you're running a demo application like MJAndroid, you still need a valid Map API Key to get map tiles from Google Maps, and you need the fingerprint of your debug signing certificate to obtain a Map API Key. You can't just use the apiKey that we have coded into the MJAndroid source files, because it is tied to the signing certificate that was generated by our debug environment. Your debug environment will generate...

The MapView and MapActivity

This book's MJAndroid application needs to be able to add overlays that show the locations for jobs in the area. So instead of using the Google Maps application, we will use a MapView, which we can overlay with as many graphics as we want. You can have only one MapView per Activity, however, and your activity has to extend MapActivity. As you'll see, that's a small price to pay for all the functionality that comes for free. There are a couple of unique prerequisites for using MapViews in your...

Gallery and GridView

The Gallery ViewGroup Figure 11-4 displays multiple items in a horizontally scrolling list. The currently selected item is locked in the center of the screen. Any items that approach the edge of the screen begin to fade, giving the user the impression that there may be more items around the corner. The user can scroll horizontally through the items within the gallery. This ViewGroup is useful when you want to present a large set of possible choices to the user without using too much screen real...

Drawables

A Drawable is an object that knows how to render itself on a Canvas. Because a Drawable has complete control during rendering, even a very complex rendering process can be encapsulated in a way that makes it fairly easy to use. Examples 12-7 and 12-8 show the changes necessary to implement the previous example, Figure 12-3, using a Drawable. The code that draws the red and green text has been refactored into a HelloAndroidTextDrawable class, used in rendering by the widget's onDraw method....

Example Determining the State of a Call

This section shows how to track the state of a phone call. It adds some of the classes described in the previous section to the application shown in Creating an Example Application to Run the call Method on page 278, which finds and uses PhoneApp to start and control a phone call. Here, in addition to starting a phone call and letting PhoneApp control it, the application gets some information about the call as it is happening. In order to get this information, we need to extend the...

Canvas Drawing

Now that we've explored how widgets allocate the space on the screen in which they draw themselves, we can turn to coding some widgets that actually do some drawing. The Android framework handles drawing in a way that should be familiar, now that you've read about measurement and arrangement. When some part of the application determines that the current screen drawing is stale because some state has changed, it calls the View method invalidate. This call causes a redraw event to be added to the...

Linkify Demo

This technique should work for demos that you can't find with the previous method. If the ApiDemos application doesn't store information about the demo in res strings.xml, it gets its information directly from AndroidManifest.xml and so will we. 1. After starting the ApiDemos application, find the particular demo through clicking on the menu, and remember the path you took through the menu system. In this case, you click on Text and then Linkify. 2. Open the AndroidManifest.xml file and search...

A Brief Tour of the MJAndroid Code

MJAndroid is a relatively simple application, despite the capabilities it gives its users. This section will give you an overview of the code and resource modules, tell you where they are located in the directory structure, and provide a glimpse of what each component does. You may want to refer to this section in the future when you're trying to find example code for a particular function and want to locate it in the MJAndroid code tree. MJAndroid uses a directory structure that is derived...

Downloading the MJAndroid Code

The MJAndroid application source code and project files are available from the O'Reilly website, at To download it to your development system, use a browser to navigate to the link given, and select Download MJAndroid. Your operating system Windows, Linux, or OS X will ask you to confirm that you want the download to happen, and ask you where to put the downloaded files. It doesn't matter where you put the downloaded, compressed files, but you want to extract the uncompressed files into the...

Exception Handling

What if something goes wrong The code in the call method that starts the dialer is wrapped in a try catch block. The catch statement contains a line of code that logs an error if the startActivity method throws an exception of the type ActivityNot FoundException. If a method can throw an exception that indicates an error, the call to that method should be in a try catch block that catches that type of exception. In this case, we use Android's logging facility to record the error. We do not...

Adding Data to an Instance of an Intent

So far, our instance of the Intent class has enough information to tell the Android system we want to start a phone call, but not enough to tell it what number to call. After creating the Intent instance with the information that means we want to call a number, in the next line we will add to it the number to call Two things happen on this line of code an instance of a Uri is created, and we use that instance as an argument to the setData method of the Intent class. Step over this line of code,...

Adding Your Own Examples to ApiDemos

The ApiDemos application is a handy sandbox for your own testing, and adding a new menu entry and Activity to it is quite easy. But remember that whenever you upgrade your API, all of your changes will be lost. Don't add code to the ApiDemo that you might want to save after an upgrade. It really is just a sandbox for quick tests. With that caveat in mind, this section shows you how to add a new menu and screen to the ApiDemos application. We'll do that by adding a new ToastTest Activity with a...

Traceview

Maybe the problem you're trying to debug isn't about functionality. Maybe your application does exactly what it's supposed to do, but takes too long to do it. Wouldn't it be nice to have a way of seeing how the methods within your classes are interacting, and even to keep track of the relative time spent executing in each method Traceview is a utility that allow you just that kind of visibility. It consists of two parts, one that you enable before running your program and one that you work with...

Android IPC Compared with Java Native Interface JNI

Remote procedure calls RPC using Android's inter-process communications largely replace the use of the Java Native Interface JNI in Android. In almost all cases, a remote procedure call is efficient enough to make it a superior alternative to loading a library especially one that dynamically allocates a significant amount of memory into the Java virtual machine's address space. And if a process exposing an RPC interface fails, it is less likely to bring down the Android UI with it. Android...

Animation

The Android UI toolkit offers several different animation tools. Transition animations which the Google documentation calls tweened animations are subclasses of android.view.animation.Animation RotateAnimation, TranslateAnimation, ScaleAnimation, etc. These animations are used as transitions between pairs of views. A second type of animation, subclasses of android.graphics.drawable.Animation Drawable, can be put into the background of any widget to provide a wide variety of effects. Finally,...

T

T-Mobile phones, running applications, 3941 TDMA Time Division Multiple Access , 306 internals, 291-302 TelephonyIntents class, 295 TelephonyManager package android.telephony , 288 TelephonyProperties class, 295 text, drawing, 230 TextView, 24, 188-191 element XML , 50 threads, 179-183 Threads Heap File Explorer pane DDMS , 35, 74 Time Division Multiple Access see TDMA TitleEditor Activity, 116 TitleEditor class, 118 toolkit, 12 tools debugging , 57 touch events, listening for, 173 touch focus,...

The androidinternaltelephony Package

This package contains the classes and interfaces PhoneApp uses to provide services to other applications that want to start phone calls, and classes that define an API to the RIL. PhoneApp, like all parts of Android, is theoretically replaceable. If your application needs to modify the classes used by PhoneApp, your application will probably have to replace or modify PhoneApp, and should provide the same services to other applications, using the classes in this package. The description of these...