Java 静态变量不';t改变并用“替换”&引用;

Java 静态变量不';t改变并用“替换”&引用;,java,android,static,Java,Android,Static,我的应用程序是一个简单的字谜游戏,因此它的级别是从Json web服务获取的,使用AsyncTaskclass我可以在doInBackground和onPostExecute方法中获取数据,我在FetchData类中使用局部变量保存获取的数据,数据只是6个字符串,是图像URL和级别id,4个单词是按钮,是游戏界面,你可以看到有4个按钮,每个按钮都有一个单词,玩家必须通过查看图片找到它 因此,当玩家找到例如1个单词并离开应用程序并关闭应用程序时,必须保存玩家找到的单词,当他返回到LevelActi

我的应用程序是一个简单的字谜游戏,因此它的级别是从Json web服务获取的,使用
AsyncTask
class我可以在
doInBackground
onPostExecute
方法中获取数据,我在
FetchData
类中使用局部变量保存获取的数据,数据只是6个字符串,是图像URL和级别id,4个单词是按钮,是游戏界面,你可以看到有4个按钮,每个按钮都有一个单词,玩家必须通过查看图片找到它

因此,当玩家找到例如1个单词并离开应用程序并关闭应用程序时,必须保存玩家找到的单词,当他返回到
LevelActivity
时,他应该通过找到更多的3个单词来继续该级别

问题是:当我找到一个单词时,该单词在我关闭应用程序并返回时显示(因此必须保存),这取决于我的测试,我发现那些影响数据延迟的代码行

注意:每当我重新加载活动(手动)时,一切都会好起来,而不是在重新创建活动后有一个空按钮,而是显示单词

使用的数据获取方法:在
onCreate
onResume

//This is in LevelActivity.java:

//These methods checks if the button is answered previously or not (button1/button2... variables are true when a word is answered)

  public void checkButton1() {

        if (button1) {
            wordButton1.setText(button1Word); //<--- Here if I changed it to .setText("Test") 
          //the lag will disappear and the button will show "Test" (without the quotation) and everything's good
          //So the problem is when I use .setText(button1Word); that is the word fetched from Json web service.
          //it doesn't throw NullPointerException and it doesn't show the word
          //but what? it set the text to " "? Why?

          //Note other buttons are the same thing too

        }

    }

    public void checkButton2() {

        if (button2) {
            wordButton2.setText(button2Word);
        }
    }

    public void checkButton3() {

        if (button3) {
            wordButton3.setText(button3Word);
        }
    }

    public void checkButton4() {

        if (button4) {
            wordButton4.setText(button4Word);
        }
    }

//这在LevelActivity.java中:
//这些方法检查按钮之前是否有应答(button1/button2…应答单词时变量为true)
公共无效检查按钮1(){
如果(按钮1){

wordButton1.setText(button1Word);//在调用

checkButton1()
checkButton2()
checkButton3()
checkButton4()

缺少。因此,按钮无法知道新值,因此保持为空。

应用程序再次启动后,您似乎再次从web获取单词。请将整个进度数据保存到数据库中,然后在应用程序再次启动后从数据库中获取数据。是否有其他方法,因为我没有足够的时间来执行此操作数据库,我正在寻找一个单行解决方案或更简单的解决方案,因为问题没有那么大,我可以重新创建()我的活动在任何时候都会打开,但它不起作用。感谢您的帮助!在这种情况下,需要更多的信息/代码。您何时开始提取数据?提取数据时您会做什么?我添加了FetchData类代码及其使用位置。:DAt
onPostExecute()
添加调用的结尾:
checkButton1()
checkButton2()
checkButton3()
checkButton4()
checkButton1()
checkButton2()
checkButton3()
checkButton4()