06-23-2010 02:26 PM
This sounds great, and exactly what I want. However, I am unclear on how to achieve this. I get how to have my screens to not call System.exit(0) but to rather request the background when they are closed. But how do I get my icon, and system menu calls to use the same instance as the start up app? Do you have a simple example or documentation or something? For instance, if I add a menu item to one of the system menus what should it call to display the screen?
06-23-2010 02:44 PM - edited 06-23-2010 02:45 PM
Have the startup application register itself as a global event listener. Define the alternate entry point with a parameter to be passed to main(). When main() detects the parameter, it knows it is running as the alternate entry and should simply post the expected global event and exit. (Conversely, absence of the parameter signals that it is the startup app.) The RIM docs on global event processing should provide the details of how to do this.
Also see this discussion.
06-23-2010 05:04 PM
One question to the original poster. Do you wish your app to be seen on the task Switcher all the time or only after the user has pressed the icon, disappearing from the task switcher when they close the app?
If you don't mind it appearing on the task switcher all the time, I see no value in having an alternate entry point. when you can just have one application, autostarted. If you do this, when the user clicks on the icon, it is bought to the foreground by the system.
If you want to remove the app from the task switcher, then I can see the use of the global event. its arrival gives you the opportunity to change the acceptsForeground() returned value, then you can foreground your app. When the last screen is popped, you can reset the value returned from acceptsForeground() to false, and go into the background.
Aside form this one potential benefit, I don't see any advantages in complicating the process using global events (which admittedly are not that complicated but still possibly unnecessary).
But that is just me!
06-28-2010 09:00 AM
Thanks Peter. I think I really like the idea of having the app run on start up and always be accessiable in the task switcher. However, I have a couple of questions that I want to get cleared up beacuse I think there are a few things I am not understanding about how everything hangs together.
1) What do you do on startup to go to the background and be able to create and display screens? I currently have two apps, a startup and one that starts when you click the icon. I tried using a firing a global event from a system menu item to my background app so that it would display a screen, however, nothing happens when I try to display the screen from the background app. The code gets hit and no error fires but nothing happens. So I am wondering if there is something else you have to do to be able to display screens from the background app.
2) When you add a menu item to one of the system menus, it seems that this is run in another app instance, niether of which are started from my main method. Is this true?
Thanks for the help on this. I think I am going to completly change my app and have it run on startup and request the background like Peter suggested, but learning about the global events has really helped my understanding of how everything works.
06-28-2010 09:07 AM
it seems you are a good learner, and ask the correct questions
1) an autostart app starts in the background. if the user clicks the icon or selects it from the task manager it is brought to the foreground.
this means you can do all kind of UI related stuff, only it is not visible until activated.
maybe you are missing a requestForeground in your processing?
2) this is correct, applicationmenuitems are executed in the context of the host application. you can use global events or the runtimestore to run code in your own application.
i do this with most items, it makes the code easier to understand and all control is in the main application.
06-28-2010 01:15 PM
This is fantastic. I have everything working the way I want. I have a background app that runs on startup and goes to the background. A menu item that sends a global event to bring it to the forground and it displays in the task switcher. Peter, I even got some help from some other threads you posted in, for instance how to re-display the screen with new data by overriding the activate method in my ui app.
I do have a couple of questions for polishing everything up. How do you set the icon that shows up in the task switch? Currently, it is showing up as just the default one, even though I have an icon on the home screen. Secondly, and maybe I should put this in another thread, but I would like my screen to be small and not take up the entire screen. So I made it smaller but the rest of the screen is just white. Is there anyway to display the previous app underneath or is this not possible because my app takes up the entire screen and I just push screens on top of this surface?
Thanks again for all the help.
06-28-2010 01:31 PM
1. Icon. I'm surprised that you are not getting the correct icon in the Task Switcher. In my experience it picks up the same icon as you have defined for the Home screen, i.e. the icon that displays in the downloads folder. Have you set your application as a System Module? What OS are you using and what IDE?
2. AFAIK, when the Blackberry OS swaps to another application, it always gives the application the whole screen. The only way to do this and to automatically have the previous application 'below' involves using Global Screen. however if you wanted to 'fake this', you could take screen shot just before your application is foregrounded, and use that as the background. I'm not sure it is worth it.
06-28-2010 02:16 PM
How about just pushing a PopupScreen instead of a MainScreen? You'll need to do all your own menu activation and display, but it should work to not take the whole screen.
06-28-2010 03:24 PM
PopupScreen I don't think works, the issue is that the BB OS has given the screen to the Application and expects it to fill it. But feel free to try and let us knowhow you get on. .
I would avoid using a Global Screen. These are good for notifications, but make some Fields impossible to use, for example, you can't use the standard date field because the Global Screen appears on top of the pop up screens that are used to change this.