Creating an Instance of an Intent

The line of code where the program stopped in the previous section looks like this: Intent callIntent = new Intent(Intent.ACTION_CALL);

This creates an instance of the Intent class. Use the "step over" command to execute this line, by selecting the Run —• Step Over option from the menu or any of the shortcuts available in Eclipse.

"Step over" does not mean "skip." Instead, it tells the debugger to run the entire line of code and all the method calls it contains (the Intent constructor, in this case) instead of entering the method calls and going through them line by line. It isn't useful to see the internals of the Intent constructor. So "step over" creates the Intent and presents you with the next line of your own code.

The debugger also has commands for "stepping into" methods and "stepping out" of the method currently being executed. These commands are more convenient than setting more breakpoints and using the Resume command.

Now that we have used the new operator and the Intent constructor with an argument that specifies we want to initialize the Intent with the Intent.ACTION_CALL constant, we have an instance of the Intent class. The action we use, ACTION_CALL, will enable Android to find PhoneApp or any other program the user may install that offers the ACTION_CALL action.

Let's take a look inside by entering the Variables view in Eclipse. You will see two columns in this view. The first column shows the names of the variables, and the second column shows their values. In our case, the names refer to instances of classes, and the values consist of the class name and the ID of the instance.

That's not very informative! Let's look inside these instances and see what they contain. Click on the triangle icon in the left margin next to the variable named callIntent. Now you see all the members of the Intent class and the values for this instance of the Intent class. The only member that has a nondefault value is mAction. Its value is the string "android.intent.action.CALL". This is the result of calling the Intent class's constructor with the argument we used.

0 0

Post a comment