这是代码
变量声明
public String gpu2dcurent = "1234567";
Asynctask,完成后它应该更新变量gpu2dcurent,但它没有
private class readgpu2d extends AsyncTask<String, Void, String> {
protected String doInBackground(String... args) {
Log.i("MyApp", "Background thread starting");
String aBuffer = "";
try {
File myFile = new File("/sys/devices/platform/kgsl-2d0.0/kgsl/kgsl-2d0/gpuclk");
FileInputStream fIn = new FileInputStream(myFile);
BufferedReader myReader = new BufferedReader(
new InputStreamReader(fIn));
String aDataRow = "";
//String aBuffer = "";
while ((aDataRow = myReader.readLine()) != null) {
aBuffer += aDataRow + "\n";
}
;
myReader.close();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
return aBuffer.trim();
}
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();
}
}
}
测试变量是否有新值。它没有,它显示 1234567
TextView tx = (TextView)findViewById(R.id.textView3);
tx.setText(gpu2dcurent);
我错过了什么吗?当我从 onPostExecute 方法内部更新 textView 时,它工作正常,但是当 Asynctask 完成变量值重置为默认值时
public class gpu extends Activity{
public String gpu2dcurent = "1234567";