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
Regular Contributor
SaMMoX
Posts: 87
Registered: ‎07-07-2010
My Device: 8520
My Carrier: Student

Update icon by background application

Hi,

I've an application that uses a background application to do something (http request). I developed the background application by using an alternate entry point get in the main application and a timer+timertask executing the thread. So at regular interval this application call a servlet, and this work.

 

My question is: is possible to change the icon of the main application based on the servlet response, so is possible to change the main icon by background application? I tried using HomeScreen.updateIcon, but this function works only if I call it from the main application, it doesn't work if the background application call this function.

 

Thanks in advance.

 

Regards,

Gianni.

Please use plain text.
Developer
StevenKader
Posts: 634
Registered: ‎02-03-2010
My Device: Z10 LE
My Carrier: Rogers

Re: Update icon by background application

You could try having another entry point in the Main program that will start a background thread that sets and waits for a global event sent from the other background app that it should change the homescreen icon.


Steven Kader at JaredCo
   Follow me on Twitter    |     Mipixi.com :  Web App for Photo Sharing
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Update icon by background application

From memory, I have seen a similar problem, that works in OS 6.0 and doesn't in OS 5.0.

 

But one thing to try:

 

net.rim.blackberry.api.homescreen.HomeScreen.updateIcon(icon, n);  // n = 0 = Normal Entry, n = 1 = Alternate Entry

Please use plain text.
Developer
amrishodiq
Posts: 112
Registered: ‎09-23-2009
My Device: Not Specified

Re: Update icon by background application

Hi, I have similar problem, and I think this problem is not solved yet,

Peter, would you give more explanation about this? A code snippet would be really appreciate.

Thanks in advance.

Please use plain text.
Regular Contributor
krishnan8727
Posts: 63
Registered: ‎10-06-2010
My Device: Not Specified

Re: Update icon by background application

if you are using the 4.5

you can use the alternate entry point

if you using 4.7 and above

we can give it in the blackberry xml configuration of the application
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Update icon by background application

@amrishodiq

Review the associated Javadoc for more information.  Here is a code sample, but I'm really not sure this is useful. 

 

Bitmap icon = Bitmap.getBitmapResource(newIcon);
if ( icon != null ) {
    net.rim.blackberry.api.homescreen.HomeScreen.updateIcon(icon, 0);  // 1 = Alternate Entry

}

 

Put this in a try/catch and note any exceptions that you get. 

 

@krishnan8727

The mathod I was describing provides a way of changing the icon dynamically, say like the mail icon changes when mail arrives.  The options you suggest change the icon once.

Please use plain text.
Developer
amrishodiq
Posts: 112
Registered: ‎09-23-2009
My Device: Not Specified

Re: Update icon by background application

Thanks for the reply Peter,

I use this method already, in method to simplify. Like this:

 

               invokeLater(new Runnable() {
			public void run() {
				try {
					if (featured) {
						HomeScreen.updateIcon(Resources.getFeaturedAppIcon(), 0);
					} else {
						HomeScreen.updateIcon(null, 0);
					}
				} catch (Exception e) {
					System.out.println("Ex: "+e.getMessage());
				}
			}
		});

Resources.getFeaturedAppIcon() returns valid bitmap object.

 

I make a class that extends Application, let say the name is BgApp. I execute this BgApp at startup using alternate entry point. Within BgApp i wrote a never ends loop that do server checkup every 2 hours (for testing, I use 2 minutes to simulate the process). If some condition met, for example there is a new entry on the server, I want to change the application icon, so I called the method containing codes above.

 

Everything goes well until the lines that update the icon. The debug said:

application already running in this process.

I do not understand why this message came, and the icon is not chaning.

 

Did I make mistake? Is this methid HomeScreen.updateIcon() has to be called within UiApplication or not?

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Update icon by background application

I don't have a very good answer here, because I've got this to work in a number of places, then I forget how I got it going.

 

Firstly I do not think you have to do this in an invokeLater.  Just execute this directly. 

 

Secondly this looks odd:

HomeScreen.updateIcon(null, 0);

Are you removing the icon?  I would have thought you would change it back to something, not nothing.

 

But really I don't know and I'm not going to find time soon to play with it.  What I would do, if I were you, is try changing the icon at start and get this working (in other words, have your background application always change the icon at start up and get this working by playing round).  As one of the previous responders has said, this should work, though it only changes it once.  You might want to try index 1 as well as index 0 too.

Let us know how you get on.

Please use plain text.
Developer
amrishodiq
Posts: 112
Registered: ‎09-23-2009
My Device: Not Specified

Re: Update icon by background application

Hey,

It's finally works. Peter sugestion is correct. The problem I told occured is because of my mistake in the other part of the code.

 

And, Peter, I use HomeScreen.updateIcon(null, 0); since the documentation said that if I update the icon to null, then the default image which is described in the project property will be used. So I think this code just fine.

 

Thank you.

Please use plain text.
Developer
mreed
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Update icon by background application

[ Edited ]

I ran into this the other day with an alternate entry point trying to update the main app icon. However if the main app hadn't started, then it wouldn't change. I ended up using the updateIcon method that accepted an ApplicationDescriptor and then made a copy of the main app ApplicationDescriptor and added some main() arguments to tell it to switch the icon then shut down (by that I mean not create an Application instance, you can call updateIcon from the main method), and used ApplicationManager (or whatever) to run the new ApplicationDescriptor.

 

edit:

Forgot to mention that you can check the ApplicationDescriptor's process id to see if it is running or not. If it is already running then you can just call updateIcon() and pass in the ApplicationDescriptor from your alternate entry point without having to use the main arguments and run it.

Please use plain text.