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
Paratheo
Posts: 134
Registered: ‎04-25-2009
My Device: Z30
My Carrier: AT&T

Running a background thread. Need advice!

Hey all,

 

I am relatively new to Blackberry java development, in fact relatively new to Java itself. Have developed for Playbook and BB10 however. That is where I am coming from.

 

Anyway, making a simple application that pulls in the Bing image of the day and sets it as the device's homescreen image. I have an option in the application that can turn this 'automatic' functionality off. So can be toggled on and off.

 

Questions about this:

 

How should I go about running such a background process or daemon perhaps, that would pull the new image from bing everyday sometime early in the morning (2-3 am)? Btw, im not asking how to get the image, I have that under control. I am specifically talking about how i could best get this 'updating everyday' functionality.

 

Keep in mind im not totally familiar with these libraries and such, so im asking advice about what would best suit my needs based on info above.

 

I appreciate any and all help given.

 

Thanks,

Theodore M.

Domisy Dev

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Running a background thread. Need advice!

Be aware, I have never done this, so this is just theory.  But this is how I would try to do it, and then look at alternatives if this did not work.

 

The first thing is you need your app to start up when the device starts up - so you set auto-start.

 

Then the question is, what sort of application is it?  There are really two sorts, foreground, which extend UiApplication and background which just extend Application.  So I think you need to start an Application since this part of the processing does not need any User Interface.  More on adding a User interface in a bit. 

 

So you will start your Application using the usual Java processing.  This application will wait for a bit, then do the business with getting the Bing background and updating the HomeScreen.  Then it will schedule itself to start up again.  To do this it will use ApplicationManager class, method scheduleApplication.  The ApplicatinDescriptor it will use is its own App Descriptor, which it can get using ApplicationDescriptor.getCurrentApplciationDescriptor.  Pretty much job done you would think.

 

But I think there are two curve balls.

 

1) How does the user switch this off?  One option is to have an icon - this will run an alternate entry to your code, only this time you wll start a UiApplication, which basically displays the Options for your app (gives the user the option of stopping it).  Search for references to alternate entry for more on this. 

 

2) Permissions.  You will possibly need to ask for permissions in order to do your network interaction to get the Bing image.  Permissions requesting involves some User Interface processing.  You might find this difficult from your Application.  But I'm not sure, I have never tried to get permissions for an Application, only ever for a UiApplication.  But if you do find it doesn't work from an Appplication, then that is another reason for having the UiApplication - if you don't have permissions you can start it and ask for the permissions and the Application will se those permissions.  And perhaps this will never be a problem for you. 

 

OK, I hope thus is enough for you to be getting on with.  But note, I have never done anything exactly like this, so this could be bum advice. 

 

Hope this makes ense and Good Luck

Please use plain text.