BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 12-05-2008, 04:50 AM   #1 (permalink)
New Member
 
Join Date: Nov 2008
Model: 8310
PIN: N/A
Carrier: no
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default How to check if application is already running?

Please Login to Remove!

I created 3 buttons that launch same application by passing different parameters. How do I determine if the application is already running so that I can avoid multiple instances of application?

Code:
private void launchApplication(String application)
{
	ApplicationManager appManager = ApplicationManager.getApplicationManager();
	try
	{
		appManager.launch(application);
	}
	catch (ApplicationManagerException ame)
	{
		Dialog.alert("Error: " + ame.getMessage());
	}
}
Offline  
Old 12-05-2008, 05:45 AM   #2 (permalink)
BBF Moderator
 
akosnitzky's Avatar
 
Join Date: Jul 2005
Location: Southern Florida
Model: 9650
OS: 6.0.0.333
Carrier: Verizon BIS
Posts: 14,484
Post Thanks: 6
Thanked 7 Times in 7 Posts
Default

Wirelessly posted (Verizon 8830)

I press Alt + ESC. Am I misunderstanding your question?
__________________
------
Follow @akosnitzky on Twitter

LET'S GO CANES!
Offline  
Old 12-05-2008, 08:08 AM   #3 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

Have you tried to get multiple instances running concurrently? You can't do it from the home screen, it may not be possible.

If it is, then I would suggest you use a persistent store to keep the application state, and check out synchronized methods.
Offline  
Old 12-05-2008, 09:50 AM   #4 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

ApplicationManager.getProcessId(ApplicationDescrip tor descriptor) returns -1 if the application is not running.

you can also use runtimestore or similar stuff to communicate.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 12-08-2008, 08:37 PM   #5 (permalink)
New Member
 
Join Date: Nov 2008
Model: 8310
PIN: N/A
Carrier: no
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks simon, I've done it using ApplicationManager.getProcessId().

Code:
private void launchApplication(String application)
{
	ApplicationManager appManager = ApplicationManager.getApplicationManager();

	try
	{
		ApplicationDescriptor[] apps = appManager.getVisibleApplications();
		int processId = -1;

		for (int i = 0; i < apps.length; i++)
		{
			if (apps[i].getName().equals(Module.name))
			{
				processId = appManager.getProcessId(apps[i]);
				break;
			}
		}

		if (processId > 0)
		{
			appManager.requestForeground(processId);
		}
		else
		{
			appManager.launch(application);
		}
	}
	catch (ApplicationManagerException ame)
	{
		Dialog.alert("Error: " + ame.getMessage());
	}
}
Offline  
Old 12-09-2008, 02:27 AM   #6 (permalink)
New Member
 
Join Date: Nov 2008
Model: 8310
PIN: N/A
Carrier: no
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have new question, how do I kill a process programatically instead of bring it to foreground and close myself.
Offline  
Old 12-09-2008, 03:47 AM   #7 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

this is not possible. you can, however, implement globaleventlistener and send a termination command as a global event.
__________________
java developer, Devinto, hamburg/germany
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.