我有条件,我通过if块处理它。但否则计时器必须停止。我试了但是没有用。我的目标,当手机是水平线(last_z> = -1.5&& last_z< = 1.5)时,应用程序将启动计时器。到目前为止没有问题。但是当水平角度失败时,计时器必须停止我不能通过else来做,因为当我写了else循环时,计时器没有解决?
if (last_z >= -1.5 && last_z <= 1.5 && dongu){
eksenx.setText("3, 2, 1 ready...");
final Handler handler = new Handler();
TimerTask doAsynchronousTask = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
Intent hazirlik = new Intent(hazirlikekrani.this,internetsiteleri.class);
startActivity(hazirlik);
System.exit(0);
}
});
}
};
Timer timer = new Timer();
timer.schedule(doAsynchronousTask, 3000);
vibrator.vibrate(500);
dongu = false;
if (last_z < -1.5 && last_z > 1.5) {
eksenx.setText("again align"); //text verisi degistirildi
timer.cancel();
}
} if (last_z > 9){
dongu = true;
}