小编Ser*_*gio的帖子

如果statment比较android java中的星期几,总是返回true

我知道这似乎是一个逻辑错误,我已经回顾了几次,一切似乎都是正确的,如果有人可以指出我正确的方向:

我们在特定时间,上午10点,下午4点和晚上11点提供服务.服务正常,通知已创建.但是,当我们将逻辑用于比较星期几时,即使它不是有问题的日子,它也会被称为每天.

代码snipet:

public void onStart(Intent intent, int startId) {
    Calendar c = Calendar.getInstance();
    int day = c.get(Calendar.DAY_OF_WEEK);
    int hour = c.get(Calendar.HOUR_OF_DAY);
    if (day == Calendar.SATURDAY || day == Calendar.WEDNESDAY); //always true
    {
        if(hour == 10 || hour == 16) //correct regardless of anterior
        {
            //create notification


        }
        else if(hora == 23)
        {
            //create other type of intent

        }
    }
    super.onStart(intent, startId);     

}
Run Code Online (Sandbox Code Playgroud)

java android calendar

1
推荐指数
1
解决办法
161
查看次数

标签 统计

android ×1

calendar ×1

java ×1