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
Developer
mbasheerk
Posts: 326
Registered: ‎02-02-2009
My Device: Not Specified

schedule job to run at specified time

I have two question.

1. I wnat to get GPS location and save it DB and send it server at 9 am and 6 pm every day in background, Can any body suggest me the better option.

2. Is there any way to notify user every day at 9 am and 6 pm like local notification as in iOS.

 

 

Trusted Contributor
imre_m
Posts: 160
Registered: ‎11-17-2010
My Device: PlayBook, Z10, Q10

Re: schedule job to run at specified time

Hi,

 

1.

I think the ApplicationManager.scheduleApplication method is what you are looking for. With this you can schedule your app to run at a specified time either in background or foreground.

To make it run every 12 hours you have to invoke scheduleApplication again when it has been launched at the required time.

 

Take a look in the API doc for details: http://www.blackberry.com/developers/docs/7.0.0api/index.html

 

2.

A solution could be to bring your app to foreground ( with Application.getApplication().requestForeground(); ) and display a notification.

You can use HomeScreen.updateIcon to change the icon of your app to signal the user that there is something going on.

There some other ideas here: https://developer.blackberry.com/bbos/java/documentation/proactive_1984360_11.html

 

Regards,

Imre

--
If you find this post useful please Like it.
If it solves your problem please mark as solution.
Developer
mbasheerk
Posts: 326
Registered: ‎02-02-2009
My Device: Not Specified

Re: schedule job to run at specified time

thanks imre for the reply

I dont think scheduleApplication is better option in my case, bcoz I have to run a piece of code evey day 9 am and 6 pm.

 

Trusted Contributor
imre_m
Posts: 160
Registered: ‎11-17-2010
My Device: PlayBook, Z10, Q10

Re: schedule job to run at specified time

scheduleApplication is an option, because it doesn't require the app to get to the foreground. It can simply run the required task, schedule the next timer and exit silently.

You can always calculate the appropriate schedule since you can get the current time. Or what is the challenge you see with this API?

--
If you find this post useful please Like it.
If it solves your problem please mark as solution.
Developer
rishikeshsinghpbh
Posts: 121
Registered: ‎05-31-2012
My Device: 9900

Re: schedule job to run at specified time

You can use RealtimeClockListener, and can put a small check in clockUpdated() method to check current time and if it is the correct time you are looking for, do the processing .

 

Also please don't do any long/lengthy process inside clockUpdated(), for any long/lengthy process use a new thread.

 

http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/system/RealtimeClockListener.h...

 

Thanks

Rishikesh Singh
Developer
mbasheerk
Posts: 326
Registered: ‎02-02-2009
My Device: Not Specified

Re: schedule job to run at specified time

will RealtimeClockListner drain the battery or is it a bad idea bcoz clockUpdated() is called every minute and my application will always run in background.?

Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900

Re: schedule job to run at specified time

[ Edited ]

no RealtimeClockListner would not drain the battery , it is method which is generated by system and it will called every minute. i have used this concept in my app and it is working fine

Developer
rishikeshsinghpbh
Posts: 121
Registered: ‎05-31-2012
My Device: 9900

Re: schedule job to run at specified time

[ Edited ]

For your following concern--

---------------------------------------------------------------------------------------------------------------------------------------------

will RealtimeClockListner drain the battery or is it a bad idea bcause clockUpdated() is called every minute?

---------------------------------------------------------------------------------------------------------------------------------------------

 

According to your need RealtimeClockListner suites best according to my knowledge and it is not a bad idea because as in your case although it will be called every minute but you require to process only two times a day.

 

-----------------------------------------------------------------------

"my application will always run in background.?"

------------------------------------------------------------------------

 

If you don't want your application to run in background all time, You can create a background app for this which will handle the RealtimeClockListener implementation and will invoke your app only if your condition matches i.e. it is 9 AM or 6PM.

 

Thanks.

 

Rishikesh Singh
Developer
mbasheerk
Posts: 326
Registered: ‎02-02-2009
My Device: Not Specified

Re: schedule job to run at specified time

my application has to be in background , has many other functions too,

my corcern is my app will run in background one listner in that (realtimeclocklistner) will invok each minute will it be a performance issue in the device.

Developer
rishikeshsinghpbh
Posts: 121
Registered: ‎05-31-2012
My Device: 9900

Re: schedule job to run at specified time

No, it will not result in Performance issue.

Thanks.

Rishikesh Singh