Algorithms and OOD (CSC 207 2014S) : Labs

Laboratory: Expanding Your App with New Activities


In this laboratory you will learn how to create more activities, and link them together in a cohesive app.

Preparation

Make sure you've completed and understood the reading on adding activities to android apps. You will find it useful to have it open in another window or tab.

Exercises

Exercise 1: Add a new activity

a. Add a new activity to the Android project you've created in the previous lab.

b. With the tools you already have, make the Activity look and do something interesting. For example you can find more meowing sounds that the cat makes on different occasions (for example if it's hungry, mad, or sleepy). If you're feeling creative, you can add some information about it, and display it as a list.

Exercise 2: Accessing our new activity

a. Add a Button to our main activity

b. Add the onClick qualifier to your new button, and decide on a method name that links lets the Button go to our other activity.

c. Implement the method you've given to your Button with a new Intent

Exercise 3: Getting back to our home screen

a. Enable the Action Bar to display the back arrow

b. Override the onCreateItemSelected method by giving it a new Intent that takes us back to our main activity

Exercise 4: Compile and Run

Run the app on your device to make sure everything is working correctly

For Those with Extra Time

Extra 1: List Views

a. Add a ListView to your activity

b. Create a new xml file that defines the rows' TextView

c. Create a list of possible pet names for your cat and feed it to the ListView via the Adapter

Copyright (c) 2013-14 Samuel A. Rebelsky.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.