[英]Android. How to stop a method's vibrations from another method
我有一種方法可以發出振動脈沖。 它使用Thread.sleep()以便在每個脈沖之間等待。 我想輸入一個STOP或RESET按鈕來阻止嗡嗡聲到達vibratorDAYONE()的結尾。 我嘗試使用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);
}
public void vibratorEnder()
{
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.cancel();
}
在vibratorDAYONE()
放置一個標記,以在vibratorDAYONE()
之前進行檢查。 在vibratorEnder()
設置標志。 如果設置了標志,則從vibratorDAYONE()
返回而不是繼續。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.