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
Highlighted
Developer
Posts: 21
Registered: ‎11-09-2009
My Device: Not Specified
Accepted Solution

start external thread with other processID, then close application

Hi,

 

this is a tricky one, so maybe something for all the magicians amongst us Smiley Wink

 

OS 4.6.0, Bold 9000, tested via Wifi and 3G networks

 

As far as my knowledge about operating systems goes, it is not possible to start a process from your own app, close the app and then update the app. This is because the started process has the processID of the app as parentID. So as long as the process is running the app is running and  accessing its cod files.

 

I am trying to get some update mechanism into my app. At the moment I am invoking a new browsersession and exiting my app (via calling onClose() on all screens on the stack or System.exit(0)) after starting the browsersessions displayPage() thread. I know, that probably would never work, but it was the easiest approach and worth a try. With both variants to close the parent app the ota download starts, but crashes at about 10%. I suppose this is because then a cod file of the application is attempted to be overwritten. According to the following threads and my previously mentioned knowledge about OSs this would be the point where the app needs to be perfectly terminated.

 

Now even after all possible ways to close an app that I know of ... even if I try to reinstall over OTA via the external browser, the download crashes at about 10% (App closed before!). Seems I am having the same problem as this guy, but calling onClose on all screens doesn't solve it.

 

Thread about problems killing a bb-app

 

After the crash the device shuts down and restarts. Unless I am starting the app again I am able to reinstall it via OTA download in the external browser. This leads me to some open handles that might be left by my app although closing it. Is there a way to really terminate the app without any leftovers? From the following KB article I read that there is some memory cleaner application running in the background. Can a cleanup of my application data be requested manually on close?

 

Thread mentioning the memory cleaner app

 

KB article about memory cleaning

 

Another approach I thought of would be writing a separat Updater app. This one would be installed via OTA out of the original app (does not affect the applications files). Then the app closes, the updater has to be run manually by the user. This one would only open a browsersession opening the ota download of the new app. Problem is still that the download would crash unless the old app was terminated properly before.

 

Any ideas about this?

 

Cheers Rob

 

 

 

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: start external thread with other processID, then close application

[ Edited ]

Your second approach would probably be the best approach provided the application doesn't have any listeners currently registered.

 

You could send a signal (Global Event) to the application to unregister all its listeners and exit then try updating it once it sends back some sort of event saying that its done unregistering.

 

You could even set up the update to be automatic with some clever programming.

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Developer
Posts: 21
Registered: ‎11-09-2009
My Device: Not Specified

Re: start external thread with other processID, then close application

[ Edited ]

 

Thanks Jerome,

 

will give it a try.

 

Regarding the update problem: Calling the external browser works fine, the only thing to beware of is not to close the app but just request the app to go to background:

 

 

synchronized(UiApplication.getEventLock()) {
	synchronized (PersistentStore.getSynchObject()) {
		UiApplication.getUiApplication().requestBackground();
	}
}

 starting the ota download after this works nearly perfectly (browser cache has to be cleared before, cod size is 650kb).

 

As for the clever programming i found this:

 

KB article about programmatically installing and updating applications

 

 

Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: start external thread with other processID, then close application

[ Edited ]

May be I misunderstood what you're saying, but it is possible to start a process from your process, then terminate your process, and then have the newly started process update your application's modules. In fact, you can update your own modules from inside your own application, but that might require a reboot to complete.

Developer
Posts: 21
Registered: ‎11-09-2009
My Device: Not Specified

Re: start external thread with other processID, then close application

Yes you got it right,

 

the CodeModuleManager api is an option, but the easiest way is to just call the external browser with the ota site opened. The user is probably used to this screen anyway, so why not.