我正在尝试设置警报,以在10秒后在我的应用中显示Toast消息,但是由于任何原因,该消息在6秒后显示,并且它忽略了我传递给setExact方法的时间:
var john = {
Billamounts: [124, 48, 268, 180, 42],
tip: [],
TipCalc: function() {
for (var i = 0; i < this.Billamounts.length; i++) {
var TIPz;
var bill = this.Billamounts[i];
if(bill < 50){
TIPz = bill * (20 / 100);
}else if((bill >= 50) && (bill <= 200)){
TIPz = bill * (15 / 100);
}else if(bill > 200){
TIPz = bill * (10 / 100);
}
this.tip[i] = TIPz;
}
return
}
}
john.TipCalc();
console.log(john.tip);
这是我的Receiver类:
AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i=new Intent(context, processTimerReceiver.class);
PendingIntent pi=PendingIntent.getBroadcast(context, 0, i, 0);
mgr.setExact(AlarmManager.RTC_WAKEUP,10000, pi);
清单中的接收者:
public class processTimerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Time is up", Toast.LENGTH_SHORT).show();
}
}
我在做什么错了?
我正在Android 8.0 Oreo设备上进行测试。