Android, java - Unable to update variable from asynctask

后端 未结 4 732
无人及你
无人及你 2021-02-11 04:51

Here is the code

Variable declared

 public String gpu2dcurent = \"1234567\";

Asynctask, after finished it should update variable gpu2dc

4条回答
  •  迷失自我
    2021-02-11 05:11

    Here is the whole code

     package rs.pedjaapps.DualCore;
    
     import java.io.BufferedReader;
     import java.io.File;
     import java.io.FileInputStream;
     import java.io.IOException;
     import java.io.InputStreamReader;
     import java.util.List;
     import java.util.concurrent.TimeoutException;
     import android.app.Activity;
     import android.app.ProgressDialog;
     import android.os.AsyncTask;
     import android.os.Bundle;
     import android.util.Log;
     import android.view.View;
     import android.widget.AdapterView;
     import android.widget.ArrayAdapter;
     import android.widget.Spinner;
     import android.widget.AdapterView.OnItemSelectedListener;
     import android.widget.TextView;
     import android.widget.Toast;
    
     import com.stericson.RootTools.RootTools;
     import com.stericson.RootTools.RootToolsException;
    
     public class gpu extends Activity{
    
    public String gpu2dcurent = "1234567";
    
    private ProgressDialog pd = null;
    private Object data = null;
    
     private class readgpu2d extends AsyncTask {
    
    
        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";
                }
    
                //gpu2dcurent = aBuffer.trim();
                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();
             }
    
         }
    
        }
    
    
    
    
        @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gpu);
    this.pd = ProgressDialog.show(this, "Working..", "Loading...", true, false);
    new readgpu2d().execute("blablabla");
    TextView tx = (TextView)findViewById(R.id.textView3);
    tx.setText(gpu2dcurent);
     }
    
    
    }
    

提交回复
热议问题