02-22-2010 02:09 PM
I have an application with two entry points. One entry point runs as a background app listening for calendar changes. When the calendar changes I need to change to icon on the Home Screen for the GUI app part of my app. However, if I'm in another application when the event occurs, the currently active application has its icon changed.
I realize there is another version of updateIcon() in 4.7 but how do I deal with this in older versions of the OS?
Solved! Go to Solution.
02-22-2010 02:43 PM
Use a Global Event to pass a message back to your Application that the Calendar has changed. Your application can then do whatever it wants, including changing the application icon.
What Is - Global Events and Global Event Listeners
Article Number: DB-00145
02-22-2010 11:34 PM
I've used global events before.
I guess it's my understanding of the process model I'm having an issue with. My background app is processing the calendar change events. But another application is active in the GUI. My GUI app is not running at all. If I post a global event, the only running process that would receive the event is the one I tried to set the icon from in the first place and it is not the active application.
02-23-2010 04:08 AM
Two clarification questions:
1) When you say you have two different Applications, the GUI and the Background app, are they actually two different Applications or is the GUI an Alternate Entry? I believed from your first post that you were using an Alternate Entry.
2) Is this what you see?
Another application is active in the GUI, and I'm presuming that it is the one making the calendar changes. So the 'listener' that you use is actually running under control of that process. So while you say "the only running process that would receive the event is the one I tried to set the icon from in the first place", I suspect the code that was running came from your Background Application, but the Application in control was not your Application. As a result, the running Application runs your Icon changing code and gets its icon changed.
02-23-2010 07:46 AM
1) It is one application with an alternate entry point. The background part starts with the device and creates a PIMListener to monitor events in the calendar app. When it finds an event of interest it is supposed to change the icon for the app.
2) Correct. If I am in the Calendar and create an event that my app finds 'interesting', when I exit the calendar to the Home Screen, the icon for the Calendar is now the icon for my app (with a notification badge). So, the Calendar application was the application in control when my background app attempted to change the icon.
If I send a global event, I assume that the Calendar will still be the app in control and therefore the wrong icon will still be updated in the gloabl event listener. So, I can see why they added the third variant of updateIcon() in 4.7 but what do you do in the older versions of the OS?
02-23-2010 07:52 AM
(most) listeners run in the context of the host app.
you have to change your application model to reflect this and be able to get into your own applications context.
one possibility would be to run an application at autostart (in the background) and use invokeLater to get into its context.
02-23-2010 09:49 AM
"If I send a global event, I assume that the Calendar will still be the app in control"
Your assumption is not correct. Your Application will be in control when the Global Event is received. So you can change your icon validly. However you will have to create an Application at startup to listen to these events. I thought you might already be doing this.
This mechanism uses Global Events to 'task switch'. An alternative is to do what Simon suggests. However I think the Global Event mechanism is a cleaner approach.
Either approach requires that you have a background Application.
02-23-2010 10:45 AM
The global event approach does work.Thank you.
Is there any documentation on the process model anywhere? I have been wondering if my understanding of how the various threads and entry points relate was correct. Obviously it was not. I'd like to have better understanding.
02-23-2010 10:49 AM
No, there is nothing about it (that i know of). Peter and I have both mentioned it many a time, maybe we should set up an own BB site with this stuff
02-23-2010 03:26 PM
I was actually thinking the same thing Simon! Or perhaps write a book and have a process chapter in it. We could also describe the proper way to Alternate Entries and how you can use Application Descriptors to start multiple versions of your application, all of which are variations on the same theme!