Android, java - Unable to update variable from asynctask

后端 未结 4 997
别那么骄傲
别那么骄傲 2021-02-11 04:39

Here is the code

Variable declared

 public String gpu2dcurent = \"1234567\";

Asynctask, after finished it should update variable gpu2dc

4条回答
  •  情深已故
    2021-02-11 05:23

    I have a doubt you are trying to set text of TextView before completion of your Asynctask.

    Yes, either make it, static public String gpu2dcurent = "1234567";

    Or, set Text of TextView in onPostExecute()

    protected void onPostExecute(String result) {
             // Pass the result data back to the main activity
            gpu2dcurent = result;
             //Toast.makeText(getBaseContext(), result,
                    //Toast.LENGTH_SHORT).show();
             gpu.this.data = result;  
             if (gpu.this.pd != null) {
                 //gpu.this.pd.dismiss();
             }
          tx.setText(gpu2dcurent);
         }
        }
    

    Update:

    After update your code in question,

    change this line,

    new readgpu2d().execute("blablabla");
    

    to

    new readgpu2d().execute("blablabla").get();
    

提交回复
热议问题