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
New Developer
Posts: 4
Registered: ‎01-22-2010
My Device: 8900
My Carrier: Vodafone Romania
Accepted Solution

Programmatically kill an application

[ Edited ]

Hello,

 

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.

 

Kind regards,

Cosmin Radu

 

P.S. My app does not listen for any external events...

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

Re: Programmatically kill an application

[ Edited ]

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.

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

Re: Programmatically kill an application

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.

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Programmatically kill an application

if its your app change it to listen for a kill command using global events or a shared runtimestore service.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Programmatically kill an application

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.

New Developer
Posts: 4
Registered: ‎01-22-2010
My Device: 8900
My Carrier: Vodafone Romania

Re: Programmatically kill an application

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

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Programmatically kill an application

it is a security mechanism

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 3
Registered: ‎10-09-2009
My Device: Not Specified

Re: Programmatically kill an application

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.

Thanks,

Jayanta

Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Programmatically kill an application

If it is your own app, or if you have a reference to the Application instance, an infinite while loop calling invokeLater() will overflow the message queue certainly.

New Contributor
Posts: 8
Registered: ‎04-11-2012
My Device: 9100
My Carrier: Airtel

Re: Programmatically kill an application

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(moduleHandle);
int processId = appMgr.getProcessId(appDes[0]);
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.