Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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 安卓如何停止方法';这是另一种方法产生的振动_Android_Android Vibration - Fatal编程技术网

Android 安卓如何停止方法';这是另一种方法产生的振动

Android 安卓如何停止方法';这是另一种方法产生的振动,android,android-vibration,Android,Android Vibration,我有一种方法可以发出振动脉冲。它使用Thread.sleep()在每个脉冲之间等待。我想输入一个停止或重置按钮,以停止蜂鸣器到达可控震源Dayone()的末端。我尝试使用v.cancel和return(),但它仍然继续使用该方法 public void vibratorDAYONE() { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); if(!v.hasVibrator()) {

我有一种方法可以发出振动脉冲。它使用Thread.sleep()在每个脉冲之间等待。我想输入一个停止或重置按钮,以停止蜂鸣器到达可控震源Dayone()的末端。我尝试使用v.cancel和return(),但它仍然继续使用该方法

 public void vibratorDAYONE()
{
    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    if(!v.hasVibrator())
    {
        Toast.makeText(daybuzzer.this,
                "You need to have a vibrator on your phone for this app to work.", Toast.LENGTH_LONG).show();
    }
    else
        {
        Toast.makeText(daybuzzer.this, "Start Running.", Toast.LENGTH_LONG).show();
        }
    v.vibrate(200); //start first
    SystemClock.sleep(2000); //Length of the first run
    v.vibrate(200);     //start second part
    SystemClock.sleep(2000);
    v.vibrate(200);
    SystemClock.sleep(2000);
    v.vibrate(200);
    SystemClock.sleep(2000);
    v.vibrate(200);
    SystemClock.sleep(2000);
}


在振动前,在振动Dayone()中放置一个标志以进行检查。在
可控震源()中设置标志。如果设置了标志,则从
可控震源Dayone()
返回,而不是继续。

我对您的问题有点困惑。您是否在单独的线程中调用了颤音DayOne(),并试图中途停止它?您何时/何地从中调用可控震源()?该方法是从addListenerOnButton方法调用的。我正试图阻止颤音DayOne()完成它的所有振动。
public void vibratorEnder()
{
    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    v.cancel();
}