Initiating a Phone Call

The next line in our program looks like this: startActivity(callIntent);

This looks like we want to start an Activity, using the Intent object we created. But why don't we need to specify an instance, or even a class, when we call startActivity? Because our program is an instance of the Activity class. We are calling a method of the class this object is an instance of. We could have used the following instead:

this.startActivity(callIntent);

Our program is already an Activity, but we now want to start a new instance of the Activity class—one that can handle the Intent instance we created. The Android framework handles the call by searching for an Intent that matches our request for ACTION_CALL. Let's step over this line and see what happens.

Now the arrow in the left margin of the code view points to the last line of the call method, just before the method returns. The emulator window shows the Android call status application displaying the number we specified. It should look like Figure 14-2, shown earlier in this chapter.

The fact that we stepped over this line of code and can now continue executing our program means that making a phone call this way is asynchronous: it allows our program to continue running while the dialer program makes the phone call.

Android is a collection of applications, and the application you are debugging places no restrictions on other applications that can be running at the same time.

0 0

Post a comment