开发者

How to always check the time on Blackberry?

I make a alternate entry point that display a dialog " Hello new week " on the first day of each week.

My code :

public static void main(String[] args)
    {
        if ( args != null && args.length > 0 && args[0].equals("autorun") ){

             MyApp theApp = new MyApp();
             theApp.pushThread.start();
             theApp.enterEventDispatcher(); 
       } 
        else {       
            MyApp theApp = new MyApp();
            theApp.pushScreen(new MyScreen());
            theApp.enterEventDispatcher();
       }        
    }


    Thread pushThread = new Thread(){
        public void run() {
            if(get_DayOfWeek().startsWith("Mon"))
            showMessage("Hello New Week ");

        }   
    };
    private void showMessage(String data) {
          UiEngine ui = Ui.getUiEngine();
          Screen screen = new Dialog(Dialog.D_OK, data, Dialog.OK,
 开发者_C百科           Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION),
            Manager.VERTICAL_SCROLL);
          ui.queueStatus(screen, 1, true);
        }

If today is Mon, it will display Dialog. But if today is Sunday, it will not display tomorrow. I want to always check the time but my code only check one time. I repalce

public void run() {
                if(get_DayOfWeek().startsWith("Mon"))
                showMessage("Hello New Week ");

            }

by

public void run() {
                    while (get_DayOfWeek() != null){
                        if(get_DayOfWeek().startsWith("Sun"))
                            showMessage("Hello New Day ");
                        }

                }

but it said "Uncaught Exception, My notifacations is not responding, the process terminated " Can anyone help me get way to always check the time ?


It is quite simple.

Implement RealtimeClockListener and use it in your application. In your implementation there will be method clockUpdated(). The BlackBerry Operating System will invoke this method every minute.

Use System.currentTimeMillis() in this method to get the current time and use Calendar class to calculate current weekday.

That's it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜