Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 28
Registered: ‎03-15-2012
My Device: BB 9810
My Carrier: Du-UAE

Alarm clock app

Dear developers,

 

I would like to get some help & feedback from you

since I'm still new in the development process

 

I would like to make an Alarm clock app

that is somehow different to the one provided on the devices

Is that possible ?

 

And how do i get the device time ?

so that i compare it with my app alarm time 

 

I read that i need to use RealtimeClockListener

and use the clockUpdated() method

but I still need guidance

 

Your help is highly appreciated

 

Thanks all,

Hussam

Developer
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

Re: Alarm clock app

You can get the current time by using

 

long timems = System.currentTimeMillis();

 

use DateFormat to format it how you'd like. You can turn it into day, time, whatever.

 

SimpleDateFormat dateformat = new SimpleDateFormat("hh:mm aa"); //check java docs for other formatting methods here

http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html

 

DateField time = new DateField("", timems, dateformat );

 

you can convert to a string if thats how you want to display

 

time.toString();

 

You can do it in the clockUpdated method, I think it is invoked every minute the clock changes.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Alarm clock app

I'm guessing, because I have seen questions like this before, that this is some kind of assignment you have been given.  Search the forum, other people have asked similar questions about creating alarm clock apps. 

Developer
Posts: 84
Registered: ‎01-10-2013
My Device: Bold 9900
My Carrier: China Unicom

Re: Alarm clock app

Hi, peter, could you please show me some idears about alarm clock app? I'm writting it now, and I'm facing some problem, thanks a lot!~

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Alarm clock app

What problems are you facing?

Developer
Posts: 84
Registered: ‎01-10-2013
My Device: Bold 9900
My Carrier: China Unicom

Re: Alarm clock app

thanks for your reply!

 

Alright....I'm tring to start 5 threads to monitor current system time, interval 1 second, for a while the blackberry resource monitor report me that my app consume many power, so I think this is not a correct way to implement an alarm clock app, do you have any suggest for me?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Alarm clock app

Why do you need 5 Threads?

 

If all you are doing is creating an alarm clock to go off at specified times, then I assume you will be setting these times in minutes.  In that case, the RealTimeClockListener is the approach you should use, because it gets a prompt every minute,

Developer
Posts: 84
Registered: ‎01-10-2013
My Device: Bold 9900
My Carrier: China Unicom

Re: Alarm clock app

The 5 threads just for efficiency test, but I want to made a multi-function alarm, it will need 3 threads at least

 

Thanks for your suggestion, I will try later~

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Alarm clock app

I doubt you need 3 Threads.

 

Remember that that BBOS is a single processor device so Threads do not run concurrently - by run here I mean use the processor.

 

In this case I would work on a single Thread which has a loop checking when next it needs to wake up.  Once it figures that out, it will just do a wait for the time left (not a sleep).  You can wake this Thread up if the user changes something, so that it can re-evaluate when it next needs to do something. 

 

To do this you will need to understand wait()/notify() to make this work properly - so research that.  This is a Java concept, not specific to BlackBerry, so you will find normal Java tutorials that talk about wait() and notify() on a shared Object. 

Developer
Posts: 84
Registered: ‎01-10-2013
My Device: Bold 9900
My Carrier: China Unicom

Re: Alarm clock app

Copy that! I will try to done all my jobs in one thread, and/or maybe by using system listener, I will try my best to find out the best way to immeplement it, you show me a very good idear, thank you peter!