所以我正在编写一个数据科学应用程序,它从几个传感器收集数据并将它们发送到下拉框。
只要sensorReading
中的数据超过500 kB
并且我的停止按钮无法正常工作,我的应用就会挂起。
这是我的代码:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_pos_poll_side: {
if (LightSensor != null || mProximity != null || mAccelerometer != null || mGyroscope != null) {
mySensorManager.registerListener(
MultiSensorListener,
LightSensor,
SensorManager.SENSOR_DELAY_NORMAL);
mySensorManager.registerListener(
MultiSensorListener,
mProximity,
SensorManager.SENSOR_DELAY_NORMAL);
mySensorManager.registerListener(
MultiSensorListener,
mAccelerometer,
SensorManager.SENSOR_DELAY_NORMAL);
mySensorManager.registerListener(
MultiSensorListener,
mGyroscope,
SensorManager.SENSOR_DELAY_NORMAL);
//print output text
side_output.setText(Html.fromHtml("<h3> ----- Data Collection Session Starts Here -----</h3>"));
} else {
side_output.setText("No Sensor Found!");
}
break;
}
case R.id.btn_stop_poll_side: {
mySensorManager.unregisterListener(MultiSensorListener,
LightSensor);
mySensorManager.unregisterListener(MultiSensorListener,
mProximity);
mySensorManager.unregisterListener(MultiSensorListener,
mAccelerometer);
mySensorManager.unregisterListener(MultiSensorListener,
mGyroscope);
side_output.append("\n" + sensorReading);
/*
Reading data and writing to Dropbox!
*/
new DropboxTask(side_output, "Back Pocket Data Reading", sensorReading).execute();
break;
}
}
}
private final SensorEventListener MultiSensorListener
= new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_LIGHT) {
numLightSensor = event.values[0];
sensorReading += "\"BackPocket\" " + String.valueOf(numLightSensor) + " " +
String.valueOf(numProximitySensor) + " " +
String.valueOf(numAccelerometer_X) + " " +
String.valueOf(numAccelerometer_Y) + " " +
String.valueOf(numAccelerometer_Z) + " " +
String.valueOf(numGyroscope_X) + " " +
String.valueOf(numGyroscope_Y) + " " +
String.valueOf(numGyroscope_Z) + "\n";
}
if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
//similar as above
}
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
//similar as above
}
if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) {
//similar as above
}
}
};
如何才能使其最佳运作? 谢谢!