samedi 31 décembre 2016

Android Studio activity - using onCreate(), onResume() etc

So, I have an activity where the user can view words he has collected, then enter a word, press the submit button, and if this word exists and uses the letters the user has available then he will be given a score which appears in a textView. Issues I have: when the user exits the activity (e.g. goes to collect more letters) and then goes back to the activity where he enters words, the current score is no longer there and the all the letters he has collected are back in there even if has used them and been removed. I understand that this issue is because the activity gets reset each time the user leaves it and enters it I just don't quite understand how to use the onCreate, onResume, onPause methods. Second issue: it seems the user can only enter one word. when I try to enter another word after having entered the first word, nothing happens even though he has letters for that word available.

my code has this structure currently

public class calculateScoreActivity extends AppcompactActivity{
//initialise variables to be used
public void onCreate(Bundle savedInstanceState){
//set variables to textViews etc
//then go to method buttonClicked()
}
public void buttonClicked(){
if the button is pressed and user input is correct go to:
updateDictionary()
calculateScore()
}
public void updateDictionary(){
remove letters used in the word the user inputted
}
public void calculateScore(){
calculate the user score
}

Am I correct writing these methods outside the onCreate? Where and how would I use onPause and onResume so that the user can pick up from where he left?

Aucun commentaire:

Enregistrer un commentaire