This project is designed as a learning tool to help get started developing Android, by creating a simple App.
This project contains a series of checkpoints. Each one is designed to build upon the last. You will learn:
- Building interfaces using XML
- Defining business logic using Activities
- Communicating between Activities
- Packaging and running an Application
- Using background processes
- Calling Web-services
This project will build a simple expense tracker app.
The feature-set of this app is as follows:
- Generate an Expense Item (With a desription and amount)
- Use a Web-service to perform a currency conversion
- Share the Expense Item
- Save the Expense Item to the file-system
There are a lot of great resources available for learning Android development. Here are a few of the resources I used when I was starting (and still continue to use today).
- Android: Getting Started - the official Google documentation
- StackOverflow - your 'dumb' question has probably already been answered here
- Vogella Android Tutorials - step-by-step tutorials about variety of Android subjects
- XDA-Developers: Android - very large community focused on open-source
Task #1 - Import Project
Use the IDE to compile and run an Application
The purpose of this task it to familiarize yourself with the developer tools. For this task, you will import the project into your local IDE, and run the App on your device or an emulator.
- Download and install the developer tools
- Import the Expense Tracker project into your workspace
- Create an emulator, or configure your device for development
- Run the app from your IDE
Task #2 - Modify user interface, and change Application name
Learn how Android uses XML to define the user interface and String resources
The purpose of this task is to understand how Android uses XML files (in the /res folder of the project) to abstract interface definition, and other resources (like String values).
- Change the title of the App from "Hello World" to "Expense Tracker"
- In the existing vertical LinearLayout, add the following Views
- Remember to sure the text in your labels is not hard-coded
Task #3 - Additional Layout Concepts
Explore additional layout containers, and use XML attributes to fine tune the interface
In this task, we will explore how to customize positioning and size of View components using XML attributes
- Replace the existing LinearLayout with a RelativeLayout
- Change the 2 EditTexts to fill the screen (instead of currently expanding to size based on text input)
- Expense Description
- Expense Amount
Task #4 - Use Image Resources
Understand how Android handles image resources to support multiple screen sizes
Because Android can support a large variety of devices (with many different screen resolutions), it is necessary to include multiple resolutions of any image you supply. This will insure they scale correctly on all devices.
- Add a red arrow to the 'Enter' button to make it more visually appealing (Hint: Use Android Tools to create Icon assets)
- Extra Credit: add validation to the 'Amount' edit feild to ensure only numbers are entered (Hint: there is an inputType attribute)
Task #5 - Implement business logic with an Activity
Use business logic to interact with interface elements
Android uses a Java Class (extending Activity) to execute business logic.
- Get a reference to the 'Expense Amount' EditText, and retreive the value it contains
- Output the current value in the EditText when the button is pressed
Task #6 - Using Activity Intents
Launch Activities using Intents
Android uses the concept of an 'Intent' to call start a new Activity from another.
- Create a new Activity that will allow the user to record more information about the expense they are recording (named DetailActivity)
- You will need to create a new XML layout and an Activity class
- Don't forget to add your Activity to the AndroidManifest.xml file
- On the Main Activity, when the user presses the 'Enter Button' - launch the DetailActivity
- The Detail Activity will be an opportunity for the user to add more details (and eventually save the expense to the filesystem)
Task #7 - The ActionBar
Understand how the ActionBar is used
Android uses a control at the top of the screen for navigation, and user interactivity. It is useful to add buttons, and other information. There is a variety of functionality built into the ActionBar, that should be leveraged to ensure platform consistency
- Add controls to the top of ActionBar of the DetailActivity
- You will need to change the API level of our App, since the ActionBar was not supported until API 14
- This will require new image assets for the menu icons (review Task #4)
- Add 2 new menu items that will eventually be used to email or share an expense item
- You will need a new menu.xml file and changes to the Activity
- Extra Credit: Implement the Email action
- Extra Credit: Enable the Share item
Task #8 - Passing data between Activities
Pass data between 2 Activities using Intent Extras
It is frequently necessary to include relevant data when starting one Activity from another. You can attach data to an Intent before sending it, which can be interpreted when the Activity starts.
- Pass the current expense data from the MainActivity to the DetailsActivity
- Display expense information on the DetailsActivity
- Extra Credit: format the currency amount in readable format
Task #9 - Accessing data from a Web Service (in the background)
Accessing Web Services using AsyncTasks
It is common to interact with Web resources to get data. It is important to do this in the background, so the user doesn't experience pauses in the interface. This task will show how to access web resources off the UI thread.
- Call a WebService to convert the expense value to a different currency
- Make sure to call the WebService in an AsyncTask (off the UI thread)
- Log the output from the Web Service
Task #10 - Change the Interface when the AsyncTask finishes
Understanding AsyncTask Life-cycle
Because we performed the Web Service call off the UI thread, we need communicate back with the interface to notify the user that results have returned.
- Place the value returned from the WebService on the DetailActivity
- During the appropriate lifecycle method of the AsyncTask, access the View object, and set the value