Monday, July 25, 2011

Making new Android project

In the succeeding posts, I will try to present my workflow in developing an android app using the RB Pace Calculator as an example.

Let's start.

From my previous post, Hello Android World! and How to get started?, I would assume that you already have the necessary things to start Android development.

In this time being, below are my development tools/platform.
1. PC - Toshiba R830 (Intel Core i5-2410M, 2.3GHz, 6GB DDR3)
2. Win7 Pro 64bit
3. Eclipse (Helios Service Release 2) with Android SDK tools.
4. Java Development kit (v1.6.0.250)
5. Samsung GalaxyS (Android v2.3.3) - used for testing my apps.

Procedure

1. Create a new Android project in eclipse.
In this case:
- Project Name: RB Pace Calculator
- Create new project in workspace.
- Build Target: Android 2.2
- Application name: RB Pace Calculator
- Package Name: com.fmvf.pacer
- [check] Create Activity: convert
- Min SDK version: 8
- Finish

2. Design the 'view' of your application.
In this case, I made
3 XML for the different views of my application namely:

  • main.xml - main view of my application.
  • about.xml - tells something about the application.
  • help.xml - provides step by step guide in using the application.

All of these are created under the 'layout' folder.

main.xml
  
help.xml
about.xml

3. Write the program for your main activity.
In this case, I will use the Activity(convert) created in step 1 as my main Activity. This is where the calculation happens for my Main view. I also made two other classes(help.java and about.java), one for each view of my application.
  • convert.java - contains the formula used in calculating the pace.
  • about.java - only contains a listener for the back button to go back to the main Activity.
  • help.java - only contains a listener for the back button to go back to the main Activity.

In both cases, the back button will call finish() to end the current Activity and resume to Main Activity.

4. Add options menu to application.
In order to access the about and help, I added an options menu to my application.


  • To create an options menu, create another xml file under res/menu/ folder. In this case, options_menu.xml. This file will contain the details for your options menu including the names and icons.


  • To show up this menu, add a menu inflater in your Activity. The action of each icon (About and Help) is decided using 'switch' method.


  • To show up the view corresponding to the icon, call a new Intent corresponding to the icon and start the new Activity. In starting the new Activity, the Main Activity will be paused.


For example, you selected 'About':

case R.id.about:
Intent myIntent = new Intent(getApplicationContext(), about.class);     //<-- new intent here
startActivityForResult(myIntent, 0);   //<--start activity here.
break;


Menu icons:
There is a default list of menu icons that can be used and you can make your own. In this case, I used the default icons.

About - ic_menu_info_details
Help - ic_menu_help

We have now created our project. The next step would be to test it if it is working fine and that would be on the next post.



1 comment: