09-26-2012 12:40 PM - edited 09-26-2012 12:45 PM
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/article
But in my case the main() is not getting called when I click on appIcon when the app is running in background. ![]()
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 ![]()
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
}
}
Solved! Go to Solution.
09-26-2012 02:21 PM
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.
09-26-2012 04:22 PM
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/article
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-Develo
09-27-2012 10:21 AM
Really thx RexDoug, my boss told me in android he doed with similar function, thx