Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 强制ToggleButton停止写入本地内存文件_Android_Performance_Android Fragments_Android Intent - Fatal编程技术网

Android 强制ToggleButton停止写入本地内存文件

Android 强制ToggleButton停止写入本地内存文件,android,performance,android-fragments,android-intent,Android,Performance,Android Fragments,Android Intent,我有一个变量MyFinalPressure,其中填充了来自传感器压力的传感器数据。如果MyFinalPressure为=至4000(4000点或40秒),则停止写入本地存储器。 但当我调试代码时,它似乎碰到了布尔值MaxPoints,并且仍在编写。我不知道我的逻辑是不是错了 你能帮帮我吗 public Boolean Store = false; Boolean MaxPoints = false; if (activity.Store) { activity.write

我有一个变量MyFinalPressure,其中填充了来自传感器压力的传感器数据。如果MyFinalPressure
=
至4000(4000点或40秒),则停止写入本地存储器。 但当我调试代码时,它似乎碰到了布尔值MaxPoints,并且仍在编写。我不知道我的逻辑是不是错了

你能帮帮我吗

  public Boolean Store = false;
  Boolean MaxPoints = false;

  if (activity.Store) {
     activity.writeToFile(MyFinalPressure);//MyFinalPressure is float of one dimension array or stream of array. 
  }
  if (MyFinalPressure==4000){  //this conditon, am trying to stop wrting to local memory. 
     activity.MaxPoints = true;
  }

FileOutputStream fileOutputStream;

 //method to write into local memory. 
public void writeToFile(final float MyFinalPressure) {
    Log.d(TAG, "writeToFile.");
    String finalData;
    finalData = String.valueOf(MyFinalPressure);


    try {
        // true here for 'append'
        fileOutputStream = new FileOutputStream(file, true);

        String Space = " ";
        byte[] convert = Space.getBytes();

        fileOutputStream.write(finalData.getBytes());

        fileOutputStream.write(convert);
        fileOutputStream.flush();
        fileOutputStream.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }


}

 //write to file.
    StartWriting = (ToggleButton) findViewById(R.id.startWriting);
    StartWriting.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (StartWriting.isChecked()) {
                Store = true;
                Toast.makeText(getApplicationContext(), "Data Starts writing into (Message.txt) file", Toast.LENGTH_LONG).show();
            } else {
                if (!StartWriting.isChecked()|| MaxPoints==true) {  //here - this is wrong logic to stop writing to my file.
                    Toast.makeText(getApplicationContext(), "Data Stored at myAppFile", Toast.LENGTH_SHORT).show();
                    String finalData1;
                    finalData1 = String.valueOf(fileOutputStream);
                    Log.i(TAG, "of_writes: " + finalData1);
                    //    Toast.makeText(getApplicationContext(), "Data_write_number:  " + finalData1.length(), Toast.LENGTH_SHORT).show();
                    Store = false;
                }
            }
        }
    });

拿出去!StartWriting.isChecked()

由于上面的if语句StartWriting.isChecked()将始终为false。然后,因为您正在检查“!StartWriting.isChecked()”,所以它将始终输入语句