800 likes | 935 Views
Android 2: A First Project. Kirk Scott. 2.1 Creating a New, Example Android Application Project in Eclipse 2.2 Creating a Virtual Device, an Emulator 2.3 Running an App on the Emulator in Eclipse 2.4 Running the Project on an Attached Device Instead of an Emulator.
E N D
Android 2: A First Project Kirk Scott
2.1 Creating a New, Example Android Application Project in Eclipse • 2.2 Creating a Virtual Device, an Emulator • 2.3 Running an App on the Emulator in Eclipse • 2.4 Running the Project on an Attached Device Instead of an Emulator
2.1 Creating a New, Example Android Application Project in Eclipse
These overheads give a general overview of getting a sample application to work • They do not look at its code, how it works, or what Android features it is making use of or depends on • The example is based on the first app given in the tutorial on the Android developer’s Web site
A New Android Application • In the Eclipse menu take the option File, New, Android Application Project • The result of this is shown in the screenshot on the following overhead
In the first box, type in the following: • My First App • The other boxes will auto-complete as shown in the following screenshot
If things auto-completed, then you click the Next > button • The next screenshots for the wizard will not be shown • Just keep on accepting the defaults and taking Next until you reach the Finish option • Do not worry about what all of the options/defaults mean
At the end of the process, the system will take certain actions • There is a progress bar at the bottom which gives some indication of what’s going on • You may have to wait a certain amount of time
The initial Welcome screen may remain visible • If so, it will cover up what has happened • Minimize anything in the way • What you expect to see is something more or less like the screenshot on the following overhead
There are several things to notice in this screenshot • The simplest is that if you can actually read the fine print, you will see that My First App is a Hello World app • Whenever a new app is created in Android using the defaults, this Hello World layout is provided by default
You’re not looking at code • The name of the layout file that is being shown has an XML extension • What you’re seeing is the layout of the output of the app
It is important to understand that at this point you are not looking at emulation of a running app • What you’re seeing is a representation of the layout as provided in the development environment
You might notice that this screenshot of the editor doesn’t look quite like the one given earlier • It doesn’t show the tools mentioned in the previous set of overheads, but it’s not exactly the same
The toolbar happens to have disappeared • It’s not a big cause for concern • In the menu under the Window option you can choose to hide or show the toolbar • If the toolbar is hidden you can access the tools through the menu
Running the Project on a Virtual Device, an Emulator • If you want to run the project using the emulator, you need to use the Android Virtual Device Manager to create a new virtual device • If you take the Android Virtual Device Manager tool (or menu option) you should arrive at something similar to the screenshot shown on the following overhead
Click the New button to create an Android Virtual Device • The window shown in the screenshot on the following overhead comes up
It’s shown on the following overhead with the drop down list for Device expanded
For initial test purposes you might choose to use the device at the bottom of the list • This is the simplest device with the fewest resources • On the following overhead the form is shown filled out with representative values for that simple device
Using Snapshot • Certain reference sources recommend using the Snapshot option • If you do select Snapshot and then make other changes, you may have troubles later • Without Snapshot things might run more slowly • It is best initially not to useSnapshot
Warning • Here is an example of what can go wrong • Suppose you wanted to emulate a Nexus 7 device • The memory option may default to a RAM value of 1024
Unfortunately, this can lead to an error where it may not even be clear that the RAM size is what is causing the error • A Web search on the error will inform you that if the RAM value to 512, things should be OK • Using the simplest device as an example, a memory size of 256 will work
Continuing with Virtual Device Creation • Once you’ve got the parameters set, click on OK • The system can drag on for a noticeable amount of time creating the virtual device • Successful completion is indicated by the appearance of the device in the list as shown in the screenshot on the following overhead
There is no final OK step after virtual device creation • You’re done—and you have to close this window • If you just minimize it, it sits there but is still the active window • To go on from here, close this window
2.3 Running an App on the Emulator in Eclipse • There are several different ways of running an app in the emulator • It is possible to create run and debug configurations which are linked to a project • This is not necessary for an initial example
Starting the emulator can take a lot of time • Trying to run the app and having that process start the emulator does not work well • It is better to begin the process of starting the emulator • Wait patiently until it is running • Then test the app on it
Starting the Emulator • The Android Virtual Device screen is shown again on the following overhead with the created virtual device in it • The screenshot shows the device as being selected and you’ll note a Start… button on the right hand side
If you click the Start button the following screen should appear • From here, click the Launch button
After clicking launch, you should see the screen with the progress bar shown on the following overhead • So far so good
Even before the previous screen goes away, or at the very least, as soon as it finishes, you should see the emulator on the screen • It’s conceivable that you’ll have to close some things to find it • It may be hidden • In any case, the initial stage of launch shouldn’t take a long time, and this is what you should see
Now You Have to Wait Patiently • The Android message on the emulated device shown in the previous screen shot will flash white for an indeterminate period of time • The emulator is still launching • As long as that process is going on, there’s nothing else that you should do except wait
Eventually, with good luck, the emulator will look as shown on the following overhead • In the screenshot that is shown, the emulator screen is grayed out • The emulator has started, but it’s taken so long that it is mimicking a device that has fallen asleep
If your emulator is grayed out, click and drag over the emulator screen with the mouse • This should wake it up, as shown on the following overhead
Click on the circle as directed • If the apps are shown, as they are in the following screenshot, you have been successful • The emulator has been launched and is running
Running the Project in the Emulator • If you want to run the project, you need a source file for the project open in the Eclipse environment • The screenshot on the following overhead shows the explorer on the left tracing the path to the MyFirstApp.java file, with that file open in the editor in the middle