【发布时间】:2016-12-31 09:15:33
【问题描述】:
所以,我有一个活动,用户可以查看他收集的单词。如果输入的单词存在并且只使用了可用的字母,那么他/她将获得一个出现在 textView 中的分数。
问题:
当用户退出活动(例如去收集更多的字母)然后回到他输入单词的活动时,当前的分数不再存在,他收集的所有字母都回来了那里即使用过它们。我知道这个问题是因为每次用户离开并进入活动时都会重置活动。我只是不太明白如何使用 onCreate、onResume、onPause 方法。
用户似乎只能输入一个单词。当我在输入第一个单词后尝试输入另一个单词时,即使他有该单词的可用字母,也没有任何反应。
我的代码目前有这个结构,
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
}
我在 onCreate 之外编写这些方法是否正确?我将在哪里以及如何使用 onPause 和 onResume 以便用户可以从他离开的地方继续?
【问题讨论】:
标签: java android activity-lifecycle