The Java Perspective is where you will spend most of your time while developing Android applications. The Java Perspective boasts a number of convenient views for assisting in the development process. The Package Explorer view allows us to see the Java projects in our Eclipse Workspace. Figure 2.2 shows the Package Explorer listing some of the sample projects for this book.
The Java Perspective is where you will edit your Java source code. Every time your source file is saved, it is automatically compiled by Eclipse's Java Developer Tools (JDT) in the background. You need not worry about the specifics of the JDT; the important thing to know is that it is functioning in the background to make your Java experience as seamless as possible. If there is an error in your source code, the details will show up in the Problems view of theJava Perspective. Figure 2.3 has an intentional error in the source code to demonstrate the functionality of the Problems view. You can also put your mouse over the red x to the left of the line containing the error for a tool-tip explanation of the problem.
One of the very powerful features of the Java Perspective in Eclipse is the integration between the source code and the Javadoc view. The Javadoc view updates automatically to provide any available documentation about a currently selected Java class or method, as shown in figure 2.4, where the Javadoc view displays information about the Activity class.
TIPS This chapter just scratches the surface in introducing the powerful Eclipse environment. If you want to learn more about Eclipse, you might consider reading Eclipse in Action A Guide for Java Developers, by David Gallardo, Ed Burnette, and Robert McGovern, published by Manning and available online at http://www.manning.com/.
It is easy to get the views in the current perspective into a layout that may not be desirable. If this occurs, you have a couple of choices to restore the perspective to a more useful state. The first option is to use the Show View menu under the Window menu to display a specific view. Alternatively, you can select the Reset Perspective menu to restore the perspective to its default settings.
Download at Boykma.Com
E l3 AndroidChapterl 0 \S Androidchapter lExample
B-ffl com.rreiifnanning.untockingandroid B E AWhereOoVouLive,java & G AWtereDcYc'JLive & Qm. or>Create(Bur*J!e)
® new OnClicklistenerQ SJ E R javd S Bit Android Library & assess res a AndrewwiPirt.xml S313 AndroidChaptir l Sample
0 E9 com,manning,unloctangandrad 3-2 ChapterTwo.iava 3 ChseterTwo orrCr«te(Byr>dle)
St [T] R.java IS aji Android Library fe assets
CI AndroidManifest.xd S ky testproject
Figure 2.2 The Package Explorer allows us to browse the elements of our Android projects.
public class ChapterTuo extends Activity (
i** Called when the activity is first ceeaced. V I " GOvectide public void encreate(Bundle icicle) t super,onCreate(icicle); setcontentvieM (R. layout .jnajft) ;
An activity is 3 single, focused thing that the user can do. Ainrast all activiies interact the user, so the Activity class taimes care of creating a window for you in which you can place your Ul windows, they can alsc be used irt other ways; 4$ floating windows (via a theme with wrdowlsf bating set) Or embedded inside of another activity (using ActivityGroup). There are two method:
» onCreate( Bundle) is where you initiates your activity. Most importantly, here you wi usually call setContcntVicwjinO with a layout resource deíinrig your UI, and using fntfrieirt6yld(ir>t • onPausefl is where you deal with the user leaving your activity. Host importantly, any changes made by the user should at this point be committed (usually to the ContentProvjder holdl
To be of use with Context,startActlvityQ. all activity classes must have a corresponding <actlv*y> declaration m their package's Andr o i dMani f e st. xml.
The Activity class is an important part of an aopicatiori's overall Ifecvcle.
Topics covered here:
1. Activity Lifecvtle
2. configuration changes
4. Saving Percent State
6. Process I ifecvcle
Activities in the system ere fftanaged as en activity stack. When a new activity is started, it is placed on the top of the stick end becomes the running activity -- the previous activity always rerr
Figure 2.4 The Javadoc view provides context-sensitive documentation, in this case for the Activity class. Download at Boykma.Com
In addition to the JDT, which compiles Java source files, the ADTs automatically compile Android-specific files such as layout and resource files. We'll learn more about the underlying tools later in this chapter and again in chapter 3, but now it's time to have a look at the Android-specific perspective found in the DDMS.
Was this article helpful?