CST2335 Lab 3
This assignment relates to the following Course Learning Requirements:
- CLR 1: Write a graphical user interface-based program, given design documents. Techniques used will be object-oriented programming, structured programming, top-down coding, and event-driven coding. CLR-2
- CLR 4: Debug program problems using manual and programmatic methods.
- CLR 7: Create GUI programs that support internationalization as well as sustainability.
Objective of this Assignment:
The following is an exercise to help you implement what you have learned in this module. It will allow you to familiarize yourself with the module content as well as practice the skills required to develop software in the Android Studio. The goal of this lab is to familiarize yourself with the Activity lifecycle. Various callback functions are called throughout the stages of starting and stopping an Activity. Also, you will learn how to launch an Activity from another activity.
Pre-Assignment Instructions:
- Review the Module 3 content in Brightspace.
Assignment Tasks:
- Create a new branch in Git. Start by selecting the Git menu in Android Studio and select Branches. In the resulting dialog click New branch and call it lab_3.
- Delete the existing activities and layouts from your lab_3 branch to start fresh.
- Create a new empty activity named MainActivity by going to File -> New -> Activity -> Empty Views Activity and update the layout to look like the following:
It has three elements, a TextView that says Enter your name, with an empty EditText below it, and a Next button. - Create another new empty activity, but this time name it NameActivity, and update the layout to look like the following:This also has three elements, a TextView that simply says Welcome!, and two buttons on the next row that say, Thank You and Dont call me that.
- Next, well finish implementing the MainActivity. It should have the following features:
- When the Next button is clicked, get the current value of the EditText, put it into an Intent and launch the NameActivity. We will be passing data back so use startActivityForResult, not startActivity!
- Click on the MainActivity class name, press Control + O and select onPause() from the list to add an override. Save the value current value inside the EditText to the SharedPreferences so it can be loaded next time the user opens the app.
- Inside the onCreate(), load the users name from the SharedPreferences and put it in the EditText. If the users name isnt yet saved in the SharedPreferences, do not put anything in the EditText.
- Implement the NameActivity next, it should do the following:
- In onCreate(), get the users name passed from the previous activity and update the TextView to welcome the user. For example, if the user entered the name Jason in the EditText in MainActivity and pressed Next, the NameActivity should show Welcome Jason!.
- If the user presses Dont call me that, set the result to 0 and return to the previous activity.
- If the user presses Thank you, set the result to 1 and return to the previous activity.
- Back in MainActivity implement the handling of the result code from the NameActivity.
- If the result code is 0, the user wants to change their name.
- If the result code is 1, the user is happy, so we can use finish to close the app.
- Ensure that all the labels and buttons in your app use the strings.xml files and are localized properly in both English and French. Use Google Translate to get the French translations of your English buttons if needed.
- Finally, include a screenshot with your Brightspace submission demonstrating to your facilitator how to access the SharedPreferences file on your emulator via ADB.Use the Android Studio terminal window to log into the phone using adb shell. From the command line, type run-as package-name. Then navigate to /data/data/package-name/shared_prefs, and display the shared preferences using more filename.xml
- Report format: Please take 3-5 snapshots of your emulator output with different outputs/use cases(app running with different windows), add a brief explanation of your code and snapshots in a word doc. Submit the word doc on brightspace in the lab folder.
- Include a link to your GitHub repository as comment on Brightspace when submitting the assignment on BrightSpace.
Heres a full recording of how the app should function:
Rubric
Criteria | Points |
The app compiles and runs without crashing | 2 |
Name get saved to SharedPreferences | 1 |
Name gets loaded from SharedPreferences | 1 |
MainActivity transitions to NameActivity | 1 |
Student can navigate to shared preferences file via ADB and display contents | 2 |
Thank You button closes the app | 1 |
Dont call me that button just returns to previous activity | 1 |
All labels and buttons support English and French | 1 |
Total | 10 |