我遇到以下代码的问题:
@Override
public void onSensorChanged(SensorEvent event) {
// check sensor type
if(started){
if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
//get sensorevents + time
outputX.setText("acclaration x:"+Float.toString(event.values[0]));
outputY.setText("acclaration y:"+Float.toString(event.values[1]));
outputZ.setText("acclaration z:"+Float.toString(event.values[2]));
long currentDateTime = System.currentTimeMillis(); //getting current time of updating
outputT.setText("Current Time:"+df.format(currentDateTime));
/* create class object
gps = new GPSTracker(MainActivity.this);
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
LatList.add(latitude);
LongList.add(longitude);
Lat.setText("Lat:"+Double.toString(latitude));
*/
//fill up the array
sensorDataTime.add(df.format(currentDateTime));
sensorDataAx.add(event.values[0]);
sensorDataAy.add(event.values[1]);
sensorDataAz.add(event.values[2]);
//for test driving play around with progressbars
if(event.values[0]>=Math.abs(3)){ barX.setProgress(100);}
else if(event.values[0]>=Math.abs(2)){barX.setProgress(50);}
else {barX.setProgress(10);}
if(event.values[2]>=Math.abs(3)){ barY.setProgress(100);}
else if(event.values[2]>=Math.abs(2)){barY.setProgress(50);}
else {barY.setProgress(10);}
}
}
if((event.values[0]>=3) && (mCountDown==null))
{ //check for boundaries in x direction of kammscheKreis
try{
mCountDown = new CountDownTimer(5000, 1000) { // 5000 = 5 sec, here starts the timer for 5 secs
public void onTick(long millisUntilFinished) {
pic.setImageResource(R.drawable.stern); //setting image to beer
Action.setText("Du hast zu schnell gebremst!!!");
}
public void onFinish() {
pic.setImageResource(0); // set the image to "transparent"
Action.setText(0);
}
}.start();
}
catch(Exception e){Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();}}
else if(event.values[0]<(-3) && (mCountDown2==null))
{
try{
mCountDown2 = new CountDownTimer(5000, 1000) { // 5000 = 5 sec, here starts the timer for 5 secs
public void onTick(long millisUntilFinished) {
pic.setImageResource(R.drawable.speedview); //setting image to speedview
Action.setText("Du beschleunigst zu krass!!!!");
}
public void onFinish() {
pic.setImageResource(0); // set the image to "transparent"
Action.setText(0);
}
}.start();
}
catch(Exception e){Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();}}
}
我将我的倒计时器初始化为公共,所以我想要的是在事件发生时阻止倒计时器,以便在这5秒内不会发生新的事件。但它不起作用。也许倒计时器从不等于null?