Thursday, February 5, 2015
Android beginner tutorial Part 2 Creating a project in Eclipse
Launch the Eclipse IDE with Android SDK built in. It will ask you to perform some one-time tasks, such as create a workspace on your hard drive.
When thats done, we can start creating our first application. To begin creating a new Android project, select File > New > Android Application Project.
A dialog box pops up, which requires us to fill out some of the general settings for our future application. The first field is called "Application Name". This is the title of your application - it appears as the name of your app in the Play Store, Manage Applications screen, etc.
The second field is called Project Name. Unlike Application Name, this isnt shown to anyone but the developer when using Eclipse. Usually, the Application Name and Project Name are the same.
The third field is called Package Name. This is basically the id of your application - usually its not shown to the user, but it is required to stay the same for all of the versions of your application. This is similar to ids in Adobe AIR descriptor files. The format is the same as packages in AS3, for example - com.kircode.codeforfood_test
Then we are required to select Minimum Required SDK. This is basically the Android version that is required to run your application. Keep in mind that the lower the version is, the bigger your audience is, but your application wont be able to use some of the newer SDK features. It is recommended to set this value to API 8, this way, according to Android development center, youre targeting 95% of the users. Thats good enough.
The next field is Target SDK. Set this to the highest API version that your application will run on. This value informs the system that the application has been tested on this API and is supposed to work without the sytem having to do any compatibility processes. If youre unsure what to select here, pick one of the modern versions - this way your application wont look dated and will still be compatible with older versions (up to Minimum Required SDK).
The next field is Compile With. This is the API version that the application will be compiled with. If the default value isnt the most recent version, its recommended to pick that.
And finally theres Theme. Pick the color theme that will suit your application. You will, of course, be able to customize every element of your application manually if you want, but choosing a Theme here is a good alternative too.
Hit next, and you should be taken to the next configuration step. Here youll see a few check boxes and fields. The first checkbox, "Create custom launcher icon", can be selected if you want to create a custom icon for your application. I do! So I always have this checked.
The next checkbox is "Create activity". Check this, because we want to generate ourselves an Activity. I will explain what an Activity is in details a bit later.
This isnt going to be a library, so dont check "Mark this project as a library". If you have "Create Project in Workspace" checked, the application project folder will be created in the workspace that you defined when you first launched Eclipse. If its unchecked, youll be able to set a custom location for your project. I think its nice to keep things organized and all development projects should be in the development workspace, so I leave this checked.
The next part consists of a checkbox and a selection menu. Its labeled as "Working sets" and the checkbox asks us if we want to add our project to a working set. Working sets are basically groups of projects that are displayed together in the menu when youre working on one of those projects. This is a useful feature and might come in handy when working on multiple applications of the same sort, or of the same purpose, or grouped together for some other reason. Right now we dont want to include our projects in any working sets.
Hit next. We can now set a Launcher Icon for our application. If you have an image ready for that, you can import it here. You can create a new icon using any of the preset clipart images or enter some text to act as an icon. You have several other tools in this window to style your icon.
Click next, and now were asked to choose what kind of activity we want to create. Now, simply put, an Activity is a window in Android. You probably know that there arent really any windows in Android at all, except for some dialog boxes, and thats true. But the way Activities behave are similar to windows in computer operating systems. For example, if we launch a game on Android, we are first taken to the main menu screen. This is an Activity. If we click "play", the game itself launches where we can actually play it. This is another Activity. It should be noted that if we didnt purposefully close the previous (main menu) activity when launching the game, it doesnt close. The main menu is still there, under the game, not visible to the user, just "sleeping" and waiting to be opened again.
The Activities have a complex life cycle, which I will explain in later tutorials. For now, you just need to understand that an Activity is a single screen that contains some content, it can be opened, paused, stopped, etc.
So right now were on the Create Activity screen, with 5 available activity types - BlankActivity, FullscreenActivity, LoginActivity, MasterDetailFlow and SettingsActivity. Think of these as of templates.
The BlankActivity is a blank page that we can fill with content.
The FullscreenActivity is a blank page also, but it hides all the UI elements of the device. This is probably most suited for games and video applications.
The LoginActivity is a simple template used for registering or logging in using email and password.
The MasterDetailFlow is a template that has a menu and a content area. It should be noted that the template is displayed differently on tablets and phones (it creates 2 columns on bigger screens where possible, and 1 column on smaller screens).
The SettingsActivity is a simple page with UI components lined up like in the settings screen of your device.
Pick BlankActivity and click Next.
Here we are asked to set the Activity Name, Layout Name and Navigation Type for our main Activity. Leave their values as they are by default - MainActivity, activity_main and None. The names are basically for the developer to remember which Activity is which. The Navigation Type dropdown box lets you select a default navigation method for your Activity. There are multiple nice and useful pre-set navigation features here, but well leave this field None for our first project.
Click Finish, wait, and youre done!
Well continue next time!
Thanks for reading!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.