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
Accepted Solution

Advice needed for "Auto-run on startup" setting

Hey all,

 

Need some advice on how to do the following.

 

I have my java app, which updates the homescreen image everyday with Bing's image of the day. The UI of the app has an option to turn this automatic feature on and off. On exit of the app, it checks this setting, and if it is turned on it starts a background thread which works to update the homescreen. (There is a single application working all of this functionality. So no separate app working as the daemon.)

 

The problem arises on resetting the device, there is nothing to start the daemon since that is handled on exit of the app. So, I need to somehow configure the app so that on startup of device, it checks for that setting and if it is turned on it starts the background thread, if not, does nothing.

 

I hope I am being clear. So right away the "Auto-run on Startup" option in the application descriptor file popped out at me, but if I use that, what can I put in the app to check the value of the setting and where is this startup handled? Or am I thinking about this situation wrong?

 

Thanks,

Theodore M

Developer
maadani
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Advice needed for "Auto-run on startup" setting

Hi @Paratheo

 

Your solution is half way there.

 

You would need to set the auto-startup flag as true but you will also need to add flag in the persistent storage which will indicate the state of the automatic feature.

 

Once the application will load at start up, it will check the flag and continue accordingly.

 

Hope that helps,

 

E.

Developer
Paratheo
Posts: 134
Registered: ‎04-25-2009
My Device: Z30

Re: Advice needed for "Auto-run on startup" setting

Thanks for the reply. I sorta did what you explained (I think).

 

So i made an alternate entry point, and set it to auto-run on startup. Then in my main() method I checked for which entry was being used and then if its the startup one, I check the value of the setting. At that point I can start the app in the background and resume it as usual.

 

Still working out getting it to run in background with the autostart setting. Cause I need to initialize the UI and service, but all in the background.

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

Re: Advice needed for "Auto-run on startup" setting

If you only want the UI started, then you need only one entry point, with auto-start specified.  Just make sure that the BlackBerry is fully started before you try anything:

http://supportforums.blackberry.com/t5/Java-Development/Write-safe-initialization-code/ta-p/444795

 

And make sure you start in the background.  Then clicking on the icon will bring you app to the foreground.  You will need to make sure that when you close you app, instead of closing it, just put your app to the background.

 

Does that make sense?

Developer
Paratheo
Posts: 134
Registered: ‎04-25-2009
My Device: Z30

Re: Advice needed for "Auto-run on startup" setting

Thank you so much, it worked perfectly!

 

It was exactly because of the 'premature intitialization' that was causing me errors.

 

It was an honor to accept your solution.