A (175)

(Tuis.) #1

522 CHAPTER 14: Android Content Providers: Providing Data to Applications


Using the Intent class’s Intent( ) constructor method, load this new dataIntent Intent object with the
current Context (this) and the ContactGalaxy.class reference.


Next, you use the .startActivity( ) method call, called off your current Context object (this), which will
then send your newly created dataIntent Intent object to the ContactGalaxy Activity subclass. This
is all done using the following four lines of Java code, which create the Java switch-case structure
that is shown in Figure 14-9:


case R.id.contact_galaxy:
Intent dataIntent = new Intent( this, ContactGalaxy.class );
this.startActivity( dataIntent );
break;


Figure 14-9. Add a case statement referencing contact_galaxy and instantiate an Intent object named dataIntent


Now that you have added the MenuItem object for your Contact Galaxy Ruler menu selection to
your app’s OptionMenu object structure, you have set up the infrastructure that is needed to add the
UI design and the database access (and write) functionality.


Just to make sure that everything is error-free and working properly, use the Run As ➤ Android
Application menu sequence and launch the Nexus One AVD. Click on the OptionsMenu ActionBar
Overflow Icon (three vertical dots) and select the Contact Galaxy Ruler option, as shown on the
left in Figure 14-10.

Free download pdf