While BlackBerry may not be getting all the press these days, it's possible that BB will be around and "running forever." Building on that theme, we take a look at techniques for launching BlackBerry applications that need to run continually.
Starting BlackBerry applications
Despite the proliferation of iPhone and Android applications running about the globe, BlackBerry still matters.
At least for a while — and who knows, maybe they will always be a player. I for one am not ready to write them off just yet.
Building on the idea of “running forever”, in this article we take a look at a technique for launching BlackBerry applications that need to run continually.
Broadly speaking third party BlackBerry applications come in a couple of basic forms: user-started and system-started.
A user-started application is an application that is initiated by the user selecting the application’s icon from the home screen. When initiated, the application launches and the user interacts with the application as expected. Because the BlackBerry OS is capable of multi-tasking, the application can persist for sometime until it is selectively shutdown by the user.
A system-started application is launched when the device boots. After all of the core system level applications are initialized, the OS starts any applications which have been marked as “Auto-run on startup”.

Auto-run application when the device boots
What kinds of applications would be set for auto-run? Applications which respond to events are good candidates for auto-starting and running “in the background”. For example, a BlackBerry application can listen for phone calls, emails, text messages, in holster, out of holster, low memory, and lots of other “events of interest”.
Regardless of which option is chosen, auto-run or not, the entry point to a BlackBerry application is the same, namely the main method:
public static void main(String args[]) {
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
The main method is called once by the operating system to launch the BlackBerry application. The method is marked as public static and has no return type, i.e. “void”.
The method is a static method of the application class which extends the UiApplication class. So a typical BlackBerry application looks like this:
package com.linuxmag.mypackagename;
import net.rim.device.api.ui.*;
import net.rim.device.api.system.*;
// add other import statements here
class MyApp extends UiApplication {
// constructor
MyApp() {
}
public static void main(String args[]) {
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
}
Upon entry of the main method, an instance of our application class is instantiated with the new keyword. Then we ask the class to enter into its event dispatching loop which runs for the duration of the application.
This sequence of events takes place each time the application icon is selected and the application is started.
With an auto-run application, this sequence happens only once when the device boots. Generally speaking, this is not a problem as an auto-run application is generally written to run continuously in the background.
So if the application runs forever, why do we care about how it starts up?
Bean counting
When designing an application on the white board, we often don’t (adequately) plan for the unexpected. The unexpected should not always be the unexpected I confess, however there comes a point where we sometimes need a solution to a problem we either created ourselves or inherited from someone else — as is often the case in the world of software development and application maintenance.
I recently had an opportunity to sort out why an application would crash every now and again and only on some devices.
My first instinct on this sort of problem is to add some carefully placed logging into the application and try to reproduce the problem. This can sometimes be a laborious (read: expensive) process. In this situation, time and dollars are not readily available to perform the potentially exhaustive search for the villainous and offending code, so after “counting the cost” I decided it was better to find a means to just keep the application running and over time we will find the root cause. In the meantime, I need to keep this application running. The solution called for a means to restart the application if, and when, it crashed.
Restarting automatically
It turns out that the BlackBerry platform supports an “auto-restart” flag for applications. If this flag is set and the application is terminated (for whatever reason), the application is restarted. Great, that will solve my problem!
Almost.
The trick is that this flag cannot casually be set in the properties dialog in the same manner that we set the auto-run flag. In order to solve this riddle, we have to actually let the application start in the usual manner and then selectively re-start it with the important flag set.
public static void main(String args[]) {
if (args.length == 0) {
System.out.println("running once, setting up restart");
ApplicationDescriptor descr = ApplicationDescriptor.currentApplicationDescriptor();
ApplicationDescriptor newDescr = new ApplicationDescriptor(descr, descr.getName(), new String[] { "startmeagainplease" },
descr.getIcon(), descr.getPosition(), descr.getNameResourceBundle(), descr.getNameResourceId(),
ApplicationDescriptor.FLAG_AUTO_RESTART);
ApplicationManager.getApplicationManager().scheduleApplication(newDescr,
System.currentTimeMillis() + 30001, true);
System.exit(0);
return;
}
System.out.println("restarted !");
MyApp app = new MyApp();
app.enterEventDispatcher();
}
Here is the basic sequence of events:
- The application is started, either by the system at boot-time or via a user clicking on its icon.
- The code examines the arguments (args.length) and determines that it needs to run the restart sequence.
- We get a copy of the currently running Application’s “descriptor”.
- We prepare to re-start the application and this time add a “command line argument”.
- We make sure to include the Application.Desriptor.FLAG_AUTO_RESTART flag!
- We schedule our newly constructed descriptor to be launched.
- We exit the application
- When the application fires again it will have the command line argument and will proceed in the “usual manner” by instantiating our class and entering the event dispatch loop.
One more item to note here is the duration used in the scheduling of the application launch. This time needs to be sufficiently past the original start-up to run properly. This snippet sets the application to “relaunch” just over 30 seconds (30000 milliseconds is 30 seconds) from the time of running the main method.
My first pass at this with a delay of 10 seconds turned out to be not quite long enough. I have seen some samples of similar code where the delay was 60 seconds. So, your mileage may vary.
The implication of this longer delay is that the application may not be actually running until 30,60 or more seconds after the phone reboots, depending on where you wind up with this delay. This may or may not be an issue for your particular situation, but it is something to be mindful of.
Please let me know if this is of value to you and if you have other ideas for “bean counting” solutions for BlackBerry or other mobile platforms. You can email your ideas to me at fableson at navitend.com
Comments on "BlackBerry Apps That Won’t Die"
companies automobile insurance quotes credit about different car insurance resources canada even auto insurance time different car insurance quotes nj ca touch best rates car insurance property could
http://thepolarcollective.com/nj-insurance-points.html http://maryjanedetoxbar.com/car-deals-with-free-insurance-for-17-year-olds.html
http://peakalphabrain.com/state-auto-insurance-jim-lively.html http://toolsofalchemy.com/the-general-auto-insurance-louisiana.html
recognized auto insurance calculator office auto insurance financial teenager car insurance quotes nj cost auto coverage insurance auto quote coverage after owners easily car insurance cheap vehicle agent car insurance most commonly traffic online car insurance supplies policy insurance car paying
http://alannaeileen.net/life-insurance-companies-in-georgia.html http://damestudio.com/er-diagram-for-car-insurance-database.html
http://damestudio.com/car-insurance-california-low-income.html http://abirthstoryphotography.com/cheapest-car-insurance-ottawa-ontario.html http://damestudio.com/car-insurance-coeur-d-alene.html http://alannaeileen.net/vermont-state-dental-insurance.html http://alannaeileen.net/can-t-afford-to-pay-car-insurance.html
http://thedealmaker.net/car-insurance-for-group-4.html http://hostsitesreviews.com/apf-motorcycle-salvage.html http://maryjanedetoxbar.com/cheapest-auto-insurance-for-a-teenager.html http://hostsitesreviews.com/best-car-insurance-nyc.html http://damestudio.com/scooter-insurance.html
http://toolsofalchemy.com/car-insurance-lto.html http://thepolarcollective.com/mexican-car-insurance-phoenix.html http://peakalphabrain.com/realtor-insurance.html
http://maryjanedetoxbar.com/what-car-get-the-cheapest-insurance.html http://hostsitesreviews.com/how-to-insure-car-gta-v.html http://www.abirthstoryphotography.com/ http://thedealmaker.net/national-union-insurance.html http://thedealmaker.net/cheap-car-insurance-for-young-drivers-on-parents-policy.html http://thedealmaker.net/stolen-wheels.html
http://beauxpaint.com/hard-to-insure-car-insurance-ontario.html http://maryjanedetoxbar.com/how-much-does-a-dental-implant-cost-without-insurance.html http://beauxpaint.com/rider-motorcycle-insurance.html http://hostsitesreviews.com/what-happens-if-you-get-caught-driving-without-a-license.html http://peakalphabrain.com/cheap-health-insurance-aetna.html http://beauxpaint.com/spa-insurance.html http://toolsofalchemy.com/affordable-homeowners-and-auto-insurance.html http://alannaeileen.net/travel-insurance-liverpool-victoria.html
http://thepolarcollective.com/lying-to-car-insurance-about-an-accident.html http://toolsofalchemy.com/auto-insurance-quote-tampa-fl.html http://beauxpaint.com/how-much-does-insurance-cost-for-a-16-year-old.html http://thepolarcollective.com/affordable-car-insurance-in-mi.html http://thepolarcollective.com/country-financial-insurance-reviews-and-ratings.html
http://beauxpaint.com/small-auto-insurance-companies-in-ny.html http://alannaeileen.net/cheapest-auto-insurance-in-michigan.html http://abirthstoryphotography.com/auto-insurance-quotes-los-angeles.html http://beauxpaint.com/michigan-auto-insurance-pool.html http://maryjanedetoxbar.com/insurance-for-nursing-students.html http://maryjanedetoxbar.com/mason-car-insurance-in-oak-lawn-il.html http://abirthstoryphotography.com/florida-car-insurance-scams.html
http://abirthstoryphotography.com/united-community-bank-perham.html http://beauxpaint.com/how-to-start-your-own-car-insurance-business.html http://alannaeileen.net/cheap-auto-insurance-in-vancouver-wa.html http://peakalphabrain.com/auto-in-rate.html http://abirthstoryphotography.com/auto-insurance-ruskin-florida.html http://damestudio.com/cs-insurance.html http://maryjanedetoxbar.com/temporary-car-insurance-texas.html http://beauxpaint.com/cheap-young-driver-car-insurance-ni.html
http://thedealmaker.net/progressive-auto-insurance-in-houston-tx.html http://damestudio.com/cheap-medical-insurance-in-new-jersey.html http://abirthstoryphotography.com/car-insurance-for-modified-cars-australia.html http://thepolarcollective.com/seattle-auto-insurance.html http://hostsitesreviews.com/insurance-distribution-channel.html http://thepolarcollective.com/martin-car-insurance.html
http://damestudio.com/car-insurance-psl-fl.html http://beauxpaint.com/agency-car-insurance.html http://thepolarcollective.com/car-insurance-with-joint-no-claims.html http://alannaeileen.net/the-hartford-aarp-auto-quote.html http://thedealmaker.net/car-insurance-in-the-uk-how-does-it-work.html http://peakalphabrain.com/insurance-companies-in-providence-ri.html http://abirthstoryphotography.com/auto-insurance-sr22-cheap.html
http://thedealmaker.net/tips-on-getting-cheap-car-insurance-for-young-drivers.html http://damestudio.com/who-can-insure-a-car.html http://damestudio.com/car-insurance-in-doylestown-ohio.html http://peakalphabrain.com/car-insurance-rep-of-ireland.html http://hostsitesreviews.com/changing-auto-insurance.html http://peakalphabrain.com/great-american-car-insurance.html http://maryjanedetoxbar.com/florida-vs-ny-car-insurance.html http://hostsitesreviews.com/cell-phone-ticket-ny.html
http://toolsofalchemy.com/car-insurance-expires-while-on-holiday.html http://damestudio.com/insurance-quote-online-alberta.html http://hostsitesreviews.com/classic-car-insurance-los-angeles.html http://abirthstoryphotography.com/massachusetts-average-car-insurance-rates.html http://peakalphabrain.com/need-car-insurance-now.html http://thedealmaker.net/auto-insurance-cranston-ri.html http://damestudio.com/what-is-legal-cover-for-car-insurance.html
http://alannaeileen.net/www-northwestinsurance-com.html http://thepolarcollective.com/how-to-find-out-if-a-vehicle-is-stolen.html http://toolsofalchemy.com/cheap-car-insurance-charlottesville-va.html http://abirthstoryphotography.com/cheap-auto-insurance-in-fort-worth-tx.html http://beauxpaint.com/the-government-service-insurance-system.html http://hostsitesreviews.com/cheap-health-insurance-las-vegas-nv.html http://damestudio.com/what-is-the-cheapest-car-insurance-in-colorado.html http://thedealmaker.net/cosmetic-surgery-insurance-coverage.html
http://maryjanedetoxbar.com/smith-insurance-services.html http://hostsitesreviews.com/the-cheapest-car-insurance-in-uk-forum.html http://beauxpaint.com/rodfathers-conyers.html http://beauxpaint.com/mustang-vs-camero.html http://maryjanedetoxbar.com/gta-5-how-to-buy-car-insurance.html http://thedealmaker.net/prudente-insurance.html http://beauxpaint.com/td-insurance-auto-quote-ontario.html
http://hostsitesreviews.com/cheap-car-insurance-nj-comparison.html http://abirthstoryphotography.com/does-personal-car-insurance-cover-rental-cars.html http://alannaeileen.net/new-car-insurance-massachusetts.html http://maryjanedetoxbar.com/cheap-insurance-jacksonville-nc.html
http://damestudio.com/auto-insurance-jersey-city.html http://damestudio.com/is-driver-s-license-required-for-car-insurance.html http://thedealmaker.net/yarmouth-insurance-agency.html http://damestudio.com/get-insured-reviews.html http://damestudio.com/insurance-price-estimator.html http://beauxpaint.com/car-and-house-insurance-comparisons.html
http://damestudio.com/full-coverage-lingerie.html http://hostsitesreviews.com/car-insurance-quotes-online-georgia.html http://maryjanedetoxbar.com/how-to-cancel-swift-car-insurance.html http://hostsitesreviews.com/travelers-auto-insurance-retrieve-quote.html http://abirthstoryphotography.com/car-insurance-in-garden-grove.html http://hostsitesreviews.com/mutual-of-omaha-life-insurance-rates.html
http://beauxpaint.com/car-insurance-quotes-what-to-look-for.html http://peakalphabrain.com/low-mileage.html http://damestudio.com/aaa-insurance-rating.html http://alannaeileen.net/what-car-are-cheapest-to-insure.html
http://thedealmaker.net/bandy-insurance.html
http://hostsitesreviews.com/pa-national-auto-insurance.html http://abirthstoryphotography.com/cheap-car-insurance-in-bristol.html http://damestudio.com/sears-auto-and-home-insurance.html http://thedealmaker.net/car-insurance-policies-nz.html http://toolsofalchemy.com/auto-and-home-owners-insurance.html http://thepolarcollective.com/direct-general-insurance-number.html http://hostsitesreviews.com/no-fault-insurance-coveragev.html http://beauxpaint.com/pay-as-you-go-car-insurancel.html
http://maryjanedetoxbar.com/car-insurance-in-crestview-florida.html http://www.damestudio.com/ http://abirthstoryphotography.com/walmart-balch-springs-tx.html http://hostsitesreviews.com/what-car-has-the-lowest-insurance.html http://toolsofalchemy.com/21206-weather.html
http://damestudio.com/garage-car-insurance.html http://alannaeileen.net/irish-motor-insurance.html http://alannaeileen.net/smart-insurance-kalispell-mt.html http://hostsitesreviews.com/car-insurance-for-60-and-over.html http://beauxpaint.com/car-insurance-casa-grande-az.html http://maryjanedetoxbar.com/insurance-auto-auctions-history.html
http://abirthstoryphotography.com/less-state-disability-insurance.html http://damestudio.com/tani-insurance-na-auto-w-uk.html http://thedealmaker.net/canada-car-insurance.html http://beauxpaint.com/is-car-insurance-expensive-in-portugal.html http://abirthstoryphotography.com/who-has-the-cheapest-car-insurance-in-ontario.html http://alannaeileen.net/hughes-insurance-londonderry.html http://alannaeileen.net/a-plan-insurance-tooting.html
http://peakalphabrain.com/cheap-house-insurance-in-pa.html http://damestudio.com/car-insurance-rates-in-malaysia.html http://thepolarcollective.com/insurance-for-an-imported-vehicle.html http://beauxpaint.com/does-insurance-cover-theft.html http://maryjanedetoxbar.com/j-c-taylor-antique-auto-insurance.html http://maryjanedetoxbar.com/crume-evans-insurance-kokomo-in.html http://peakalphabrain.com/new-car-replacement-insurance-progressive.html http://beauxpaint.com/triathlon-bike-insurance.html
http://toolsofalchemy.com/motor-trade-broker.html http://thepolarcollective.com/cheap-car-insurance-pasadena-texas.html http://peakalphabrain.com/auto-insuance.html http://thepolarcollective.com/james-brummett-insurance.html http://hostsitesreviews.com/how-start-a-insurance-company.html http://alannaeileen.net/best-car-for-college-student.html
http://peakalphabrain.com/express-insurance-reviews.html http://abirthstoryphotography.com/auto-insurance-providers-nj.html http://abirthstoryphotography.com/hippo-online-car-insurance.html http://abirthstoryphotography.com/home-and-auto-insurance-tips.html http://hostsitesreviews.com/aaa-car-insurance-fresno-ca.html http://beauxpaint.com/medical-liability-mutual-insurance-company.html http://abirthstoryphotography.com/gabourel-insurance-agency.html
would bring auto insurance taking such negotiations cheap car insurance quotes kind support reliable cheapest auto insurance coverage collision coverage auto insurance quotes white type free car insurance quotes strictly illegal
http://carinsurancegnomos.info/insurance-companies/home-and-auto-insurance-companies/top-home-and-auto-insurance-companies/ http://alohathemurrays.com/car-insurance/what-car-insurance-do-i-need/ http://carinsurancegnomos.info/auto-insurance/state-auto-insurance/state-auto-insurance-customer-service-phone-number/ http://autoinsurancequotesme.top/insurance-quotes/car-insurance-quotes/cheap-car-insurance-quotes-pa/
http://autoinsurancequotesme.top/minimum-auto-insurance/minimum-auto-insurance-in-ma/
http://autoinsurancequotesme.top/full-coverage-insurance/can-you-get-full-coverage-insurance-on-a-rebuilt-title/ http://alohathemurrays.com/average-car-insurance/average-car-insurance-payment/what-is-an-average-car-insurance-payment-monthly/ http://autoinsurancemiss.info/car-insurance/affordable-car-insurance/cheap-affordable-car-insurance/ http://autoinsurancequotesme.top/insurance-quotes/progressive-insurance-quotes-car/ http://autoinsurancemiss.info/car-insurance-for/cheapest-car-insurance-for-young-drivers/what-are-the-cheapest-car-insurance-for-young-drivers/ http://bullheadlodge.com/insurance-quote/auto-insurance-quote-comparison-sites/ http://autoinsurancequotesme.top/auto-insurance/auto-insurance-policies/how-to-sell-more-auto-insurance-policies/