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
Developer
Posts: 90
Registered: ‎04-03-2012
My Device: 9100
My Carrier: movilnet
Accepted Solution

main method of entry point issue

[ Edited ]

i decide make a new post, because is know where is my problem extactly.....

 

i found  this : The alternate entry is going to call the main method with the parameter that is passed in, regardless of whether the application is running.  on this post http://supportforums.blackberry.com/t5/tkb/articleprintpage/tkb-id/java_dev@tkb/article-id/206 

 

But in my case the main() is not getting called when I click on appIcon when the app is running in background. Smiley Frustrated

WTF!!!  o.O!!

 

 

if u see the last invokeLater implementation above the enterEventDispatcher, u can realize it will show that dialog everytime the main method pass through there, but is not showing any dialog...  what is wrong??? i need finish this push thing Smiley Frustrated

 

static void main(String[] args) {
		String launch = null;
		if (args != null && args.length > 0) {
			launch = args[0];
		}

		if (launch != null) {
			if (launch.equals("background")) {
			
                        //Some Listener.....

			} else if (launch.equals("gui")) {
				//checking if the app is runnung...
				RuntimeStore appReg = RuntimeStore.getRuntimeStore();
				synchronized(appReg){
				   if (appReg.get(GUIID) != null){
				       UiApplication MyApp = (UiApplication)appReg.waitFor(GUIID);
				       MyApp.requestForeground();
				       MyApp.invokeLater(new Runnable() {
						
						public void run() {
							Dialog.alert("Ya etaba abierta -> request foreground a pata");
							
						}
					});
                                          return;
				       				      
				   }								
				}
				// is not running soo get the instance and make some things ...
				SingletonPushInfo sngPushInf = SingletonPushInfo.getInstance();				
				getUiApp();				
				
				if (! sngPushInf.isEmpty() ) {
					String strPush = sngPushInf.getLastPush();
					final ParsePush parsePush = new ParsePush(strPush);
					UiApplication.getUiApplication().invokeLater(
							new Runnable() {
								public void run() {
									_uiApp.pushScreen(new SearchScreen(parsePush
															.getMessage(),//
															parsePush.getNotificationType()));
								}

							});	
					if( sngPushInf.isEmpty() ){
						SingletonNotification singleNotifiIcon = SingletonNotification.getInstance();
						singleNotifiIcon.setVisible(false);
					}
					
				}
				_uiApp.invokeLater(new Runnable() {
					
					public void run() {
						Dialog.alert("always pass ....   main entry point");
						
					}
				});
				_uiApp.enterEventDispatcher();
				
			}
		}
	}

	private static  void getUiApp() {
		RuntimeStore appReg = RuntimeStore.getRuntimeStore();
		synchronized(appReg){
		   if (appReg.get(GUIID) == null) {
		       appReg.put(GUIID,UiApp.getInstance());
		       
		   }
		   _uiApp = (UiApplication)appReg.waitFor(GUIID);		  
		   //then you have the app MyApp... return it or whatever
		}
		
	}

 

 

Highlighted
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: main method of entry point issue

Put a trace in UiApplication.activate().

 

I think you'll find that this is the only call you'll get if you are running in background.

 

 

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

Re: main method of entry point issue

And note that you have copied selectively from the KB article.  You note:

 

"i found  this : The alternate entry is going to call the main method with the parameter that is passed in, regardless of whether the application is running.  on this post http://supportforums.blackberry.com/t5/tkb/articleprintpage/tkb-id/java_dev@tkb/article-id/206 "

 

However you miss the preceding sentence which is most important:

 

"If an application is designed such that the icon is an alternate  entry point, you must make the main()method avoid  creating a new instance of an application that is already running."

 

So for example, you could specify that your application autostart using the application argument "start-up".  Your icon must be an alternate entry and could specify "icon".  The code in the 'icon' path of main() would just find the (background) application in RuntimeStore and bring it to the foreground.

 

In your case however you seem to be trying to do two things with one parameter - your "gui" parameter.  This seems to both create the Application instance in RuntimeStore and if it is already there, bring it to the foreground.  But in fact, the OS will not invoke main() if there is an instance of your Application with the same start-up parameter already running. 

 

So create your application using "background" and just foreground it using "gui".

 

You should be aware of this:

http://supportforums.blackberry.com/t5/Java-Development/Write-safe-initialization-code/ta-p/444795

 

Developer
Posts: 90
Registered: ‎04-03-2012
My Device: 9100
My Carrier: movilnet

Re: main method of entry point issue

Really thx RexDoug, my boss told me in android he doed with similar function, thx