More on Bundles

We need to pass the selected job to the ShowJob Activity, but we cannot casually pass an object from one Activity to another. We don't want the ShowJob Activity to have to parse the list of jobs again; otherwise we could simply pass back an index to the selected job by using the integer storage methods of a Bundle. Perhaps we could store the currently selected JobEntry (and JobList for that matter) in a global data member of the Application object, should we have chosen to implement one. If you recall in chapter 1 when we discussed the ability of Android to dispatch Intents to any Activity registered on the device, we want to keep the ability open to an application other than our own to perhaps pass a job to us. If that were the case, using a global data member of an Application object would never work! Never mind for the moment the likelihood of such a step being low, particularly considering how the data is stored in this application. This chapter's sample application is an exercise of evaluating some different mechanisms one might employ to solve data movement around Android. The chosen solution is to package the data fields of the JobEntry in a Bundle © (in listing 12.15) to move a JobEntry from one Activity to another. In the strictest sense, we are moving not a real JobEntry object but a representation of a JobEntry's data members. The net of this long discussion is that this method creates a new Bundle by using the toBundle() method of the JobEntry.

Unlocking Android

Big Tristan's imports

2200 East Cedar Ave FlagstaffAZ

Product: UnwiredTools UTCIS PT

Comments; Requires tuning ■ too rich !n the mid range RPM. Download software from website before visiting.

Map Job Location capable device and toolbox. To help in the discussion of the different features available to the user on this screen, take a look at figure 12.10.

The layout is very straightforward but this time we have some Buttons and we will be changing the textual description depending on the condition of a particular job's status. A TextView is used to present job details such as address, product requiring service, and comments. The third Button will have the text property changed, depending on the status of the job. If the job's status is marked as CLOSED, the functionality of the third button will change.

To support the functionality of this Activity, first the code needs to launch a new Activity to show a map of the job's address, as shown in figure 12.11.

The second button, Get Product Info, launches a browser window to assist the user in learning more about the product he is being called upon to work with. Figure 12.12 shows this in action.

The third requirement is to allow the user to close the job or to view the signature if it is already closed, the details of which are covered in the next section on the CloseJob Activity.

Get Product Info

Figure 12.10 An example of a job shown in the ShowJob Activity

Figure 12.10 An example of a job shown in the ShowJob Activity a SIL a 2:43 AM

2200 E Cedar Ave

Address:

2200 E Cedar Ave Flagstaff, AZ 86004

Figure 12.11 Viewing a job address in the Maps application

Figure 12.12 Get Product Info takes the user to a web page specific to this job.

Fortunately, the steps required for the first two operations are quite simple with Android—thanks to the Intent. Listing 12.16 and the accompanying descriptions show you how.

0 0

Post a comment