我正在构建一个Android应用程序,需要满足特定条件的情况下,在特定的时间间隔内要短暂振动。
问题在于,当满足这些条件时,即使将设备设置为振动2秒,有时它也会振动10秒钟以上,并且有时振动不会停止,直到重新启动设备为止。 另外,我注意到处理程序中的runnable不在正确的时间间隔内运行。应该每隔 interval 秒,但通常花费的时间更多。
这是一个例子:
fullBatteryHandler.postDelayed(new Runnable() {
@Override
public void run() {
if(isBatteryFull){
Log.d("vibrate", "full battery");
v.vibrate(VibrationEffect.createOneShot(2000, VibrationEffect.DEFAULT_AMPLITUDE));
}
fullBatteryHandler.postDelayed(this, interval * 1000);
}
}, 1000);
为什么会发生这种情况?
编辑:我通过添加WakeLock解决了该问题。
答案 0 :(得分:0)
尝试一下:
protected function authenticated(Request $request, $user) {
if ($user->PRIVILEGE == 'C') {
return redirect()->route('/users');
} else if ($user->PRIVILEGE == 'B') {
return redirect('/blog');
} else {
return redirect('/');
}
}