android:不在Thread on Service上工作日历

时间:2014-08-13 14:48:27

标签: android multithreading service calendar

我是android的新手。我有一点问题。我在服务类中有这样的代码:

public void doWork() throws Exception{

    mHandler.post(new Runnable(){

        public void run(){

            Calendar cal = Calendar.getInstance();
            cal.setTimeInMillis(System.currentTimeMillis());

            cal.set(Calendar.HOUR_OF_DAY, 21);
            cal.set(Calendar.MINUTE, 14);

            long noon_start = cal.getTimeInMillis();

            cal.set(Calendar.HOUR_OF_DAY, 21);
            cal.set(Calendar.MINUTE, 16);

            long noon_end = cal.getTimeInMillis();
            long now = System.currentTimeMillis();//current time

            if(now > noon_start && now < noon_end)
            {

                if (show.active==false){
                    showIt();
                }


            }else{ //close activitis

                if (show.active==true){

                    sendBroadcast(new Intent("close"));
                }

            }
        }

}); 

}

我想如果时间21:14 - 21:16,请展示新的活动。否则,密切活动。它有效,但是当显示新的活动时,1秒后,它会关闭。再次显示并关闭。继续那样。

我尝试这个,它有效,

    Date dt = new Date();
    int minutes = dt.getMinutes();

            if (minutes%2==0){


                if (show.active==false){
                    showIt();
                }


            }else{ //close activitis

                if (show.active==true){

                    sendBroadcast(new Intent("close"));

                }
}

我该怎么办? 请帮忙

0 个答案:

没有答案