01-22-2010 04:32 AM - edited 01-22-2010 04:35 AM
The application I am currently working on sometimes hangs completely while testing and I can no longer terminate it. The only solution I have found is to "turn off" the device and pull the battery out. This results in an OS crash when phone reboots. I get "App error 200" and can only reset over and over again. I can connect to the device and uninstall my app so that the os starts again. So, in order to avoid all this fuss, I would like to write a small ap that kills my other application. Any hints on how I could do that are kindly appreciated.
P.S. My app does not listen for any external events...
Solved! Go to Solution.
01-22-2010 05:52 AM - edited 01-22-2010 06:05 AM
Welcome to the forum.
Unfortunately there is no way to do this. Sorry.
Correction, following on the post below, this should read there is no published API to kill an application. I'm not sure that the first approach will kill the application if there is no GlobalEventListener, but I've never tried it. I must also admit I have never managed to kill an application on the device by repeatedly hitting keys either, in theory it should work, perhaps I always give up too soon.
01-22-2010 06:00 AM
Try bombarding it with a torrent of global events using ApplicationManager.postGlobalEvent(int processId, ...) to make its process's event queue overflow forcing the OS to kill the process. I haven't tried this myself though.
You could also try switching to the frozen application and then generating lots of keyboard and trackwheel/trackpad input events very quickly, again, with the view of overflowing the process's event queue.
01-22-2010 07:02 AM
if its your app change it to listen for a kill command using global events or a shared runtimestore service.
01-22-2010 07:18 AM
Good point! The downside of kill command as a global event is that the event thread is typically frozen (the GUI doesn't repaint and that's how users notice the app is frozen), so the command won't be processed. But a kill command via a different mechanism, utilizing a thread other than the event thread might definitely work.
To elaborate on the idea, you could simply have a special kill-daemon thread running at all times in the background of your app. The thread will periodically check whether a particular other app is running. If it is, the thread will terminate its process. This way there's no need for sharing anything via the RuntimeStore. To kill your frozen app you'll simply need to start that special app which is being polled for.
01-22-2010 07:37 AM
Thank you all for your ideas. I have followed simon_hain's idea and implemented the global event mechanism. Still, a question remains unanswered: if RIM has an unpublished API that can be used to kill a process, why didn't they implement this feature in the OS itself. It is very frustrating as a user not to be able to stop an application. And it is even more frustrating for developers when testing their applications, since apps may crash quite a few times. (I also have to add that a BB Bold that I am testing on, takes 10-15 minutes to reboot - waste of time).
Again, thank you for the feedbak. Regards
01-22-2010 07:41 AM
it is a security mechanism
02-26-2010 04:55 PM
Adding to the original question - How do we kill a "third-party and non-system" CLDC/Midlet application?
I read the post of bombarding process queues using postGlobalEvent() in an attempt to overflow the queue so that system may remove that app/process. However, this does not look like a clean solution + if the certain hidden/background non-UI processes do not implement global listener, I wonder bombarding from another app would work or not - I guess not.
02-26-2010 06:27 PM
05-01-2012 10:25 PM
if you want to kill a background application from an app which is in forground then implement the following code in the foreground app -
ApplicationManager appMgr = ApplicationManager.getApplicationManager();
int moduleHandle = CodeModuleManager.getModuleHandle("AppName");
ApplicationDescriptor appDes = CodeModuleManager.getApplicationDescriptors(module
int processId = appMgr.getProcessId(appDes);
appMgr.postGlobalEvent(processId, 0x12345678, 0, 0,null,null);
And in the app running in the background, implement it with GlobalEventListener interface and overrides the evenOccured method and call the System.exit(); to forcefully close the background running app.