This week we've demoed a simple quiz app in class. While simple it includes a number of key components. We've also learned about:
I'm exhausted just reading that list. Don't worry if you don't fully understand that list -- that's what the course is all about: reinforcing the Android programming framework. But why writing code with you in class this week we went through the complete workflow. Meaning more complex applications while more sophisticated (e.g., more complex UI, services, fragments, etc) follow this framework more or less.
OK. We build a simle quiz app but it's flawed. There are at least 3 edge cases that make our simple app fail. What I want you to do is understand these edge cases and clear them. The code you will write is frankly trivial but the fact that this is your first week being exposed to Android will require you to understand how the various components work -- for example, when you rotate the phone the app goes through the lifecycle and would display the first question again but a good app would carry on displaying the current question the user has nagivated to (using the next or previos buttons). In this case an understand of lifecyle is necessary. And there is a need to store some data before the app stops and then when its restarts you need to get that data (which would represent the current question) and redisplay the current question and not as now, the first question. That's an edge case. There are 3. You need to solve them.
Here is the apk for the DartQuiz app with the edges cases solved. But at least one more remains (see extra credit). You can use this to test your app.
Figue 1: ------ Action: Launched QuizActivity view
Figue 2: ------ Action: clicked on Cheat started CheatActivity
Figure 3: ----- AAction: cliched Show Answer and answer is displayed
Figure 4: ----- Action: back keys to QuizActivity and answered the question but got caught!
Here is more information on the 3 edge cases:
EDGE: The user can still cheat (darn it) by rotating the CheatActivity. You need to fix this. Specifically, the user can hit the cheat button and show answer button (now they know the answer), and then (sneakly) rotate the phone, back key to the QuizActivity and answer the question -- without being caught cheating. For this edge case you have to also refresh the current answer (true or false) in the CheatActivity. So for example if the user clicked show answer on the question "Do Arsenl suck?" and the answer (as everyone knows) is true, then once the user rotates the answer "true" should be redisplayed.
FIX this so that when the user back keys the QuizActivity still knows they cheated. Also, if you rotate the answer will disappear. You need to redisplay the answer (true or flase).
HINT: Implement the Lifecycle in the CheatActivity (you don't actually need the states but why not just implement all the methods as we did for QuizActivity just for fun -- make use command N magic and automatic code generation). You'll need a member variable to keep account of if the user actually clicked show answer. You need to save that data during rotation and recover it when the lifecycle restarts the app. Then you need to update the result returned why the extra in the intent that is returned to QuizActivity. There are two fixed to this edge case. The first is keeping account of if the user cheated during rotation. The second is refreshing the answer which is lost during rotation. Similarly you'll need a variable that is saved and retored in the lifecycle and then you redisplay the answer -- true or false.
Make the FIX and test it. Nailed? OK. Let's move on to the next edge where our user can still cheat.
EDGE: The user can cheat then back key from the CheatActivity then rotate and then answer the question by clicking the TRUE or FALSE buttons -- and darn it -- not be caught. We are an ethical group and we have to close this door class. OK.
HINT: Think about this. You know how to fix it. Just do it!
Make the FIX and test it. Nailed? OK. Let's move on to the next edge where our user can still cheat!
EDGE: Just when we thought we'd nailed this yeh? A user can cheat on a question -- yes Arsenal suck -- and then key back around to the same question they cheated on "Do Arsenal Suck?". Right now the user knows the answer because they previously cheated on it. And the app will let then click TRUE ("Do Arsenal suck?) without castigating them as a cheater.
HINT: CheatActivity returns data indicating in the user cheated on a question to QuizActivity. There are N questions in our mQuestionBank. We need to maintain state in the data structure -- or model layer -- that maintains if the user cheated or not on any question. So when the user comes around to that question the app need to check not only if they got the answer correct or not but if they'd already cheacted on the question. If so instead of getting the correct or incorrect response displayed they get their due judgement.
I know of at least one more but there could be more. Fix then and tell us about them for an extra credit. Have fun. And I hope this exercise reinforces that cheating like Arsenal sucks....