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
New Developer
Posts: 18
Registered: ‎01-22-2010
My Device: BB 9000
My Carrier: Rogers
Accepted Solution

HomeScreen.updateIcon updates the wrong application from background

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?

 

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

Re: HomeScreen.updateIcon updates the wrong application from background

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
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/What_Is...

New Developer
Posts: 18
Registered: ‎01-22-2010
My Device: BB 9000
My Carrier: Rogers

Re: HomeScreen.updateIcon updates the wrong application from background

Thanks Peter,

 

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.

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

Re: HomeScreen.updateIcon updates the wrong application from background

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. 

 

 

New Developer
Posts: 18
Registered: ‎01-22-2010
My Device: BB 9000
My Carrier: Rogers

Re: HomeScreen.updateIcon updates the wrong application from background

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?

 

 

 

Highlighted
Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: HomeScreen.updateIcon updates the wrong application from background

(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.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: HomeScreen.updateIcon updates the wrong application from background

"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. 

New Developer
Posts: 18
Registered: ‎01-22-2010
My Device: BB 9000
My Carrier: Rogers

Re: HomeScreen.updateIcon updates the wrong application from background

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.

 

 

Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: HomeScreen.updateIcon updates the wrong application from background

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 Smiley Happy

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: HomeScreen.updateIcon updates the wrong application from background

Snap!

 

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!