Building the Activities

Up to now, you have created only single-Activity applications. This is to say, you have created rather simplistic applications that encompass only one "screen" of data. Take a minute, and think of the last few applications you have used. Chances are, they used more than one "window." Most applications use multiple windows to gather, display, and save data. Your Android applications should be no different.

Although you have not yet learned how to create multiple-Activity applications that run on Android, you got a hint about how to leverage multiple Activities in the last chapter. You used a new concept called Intents to call—and run—a core Android Activity. While the concept still holds true in this chapter, the execution is slightly different when you want to call Activities that you have created, as opposed to calling core Android Activities.

The first thing you need to do is build the Activities. Then you can create the Intents that will call them. When building the Activities, you need to follow a three-step process.

• Intent code for the .java file

• Calling Activities using an Intent

Once you create your first additional Activity, the rest should come very easily.

Remember that all Android Activities comprise three main parts: the .java file that contains the code, the .xml file that holds the layout, and the package's Manifest. To this point in the book, you have only used main.xml to control the layout of a single Activity. However, to take advantage of having multiple Activities, you must have multiple .xml layout files.

To create a new .xml file, open your Eclipse project and navigate to the Package Explorer. Open the res directory, right-click the layout folder, and choose New | File

hi: fcdrt $0HKt K-tn'Jjjr Nawyite Jffcth frOjeSt Kui" WiN'J'*#r Heb n - ^ - o - - iS B © - I.' -

hi: fcdrt $0HKt K-tn'Jjjr Nawyite Jffcth frOjeSt Kui" WiN'J'*#r Heb n - ^ - o - - iS B © - I.' -

; vilutj Q AriiJiunlManifiiljrnl

Cupy Qu »lifted N irnc

; vilutj Q AriiJiunlManifiiljrnl

Cupy Qu »lifted N irnc

In the New File dialog box, shown next, name your file test.xml.

^ New File

■=■ InSHSM

File

Create a new file resource.

Enter or select the parent folder: An d ro i dVi ews/re s/l ayo ut

Enter or select the parent folder: An d ro i dVi ews/re s/l ayo ut

AndroidViews assets & bin & res drawable & layout values

0 0

Post a comment