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

Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

What limts on find a resource at startup and use image to set as an icon using HomeScreen?



I copied some examples for setting the app icon and they more or less work. However,

I have an odd problem apparently related to finding the images.

I've got one set of images that seem

to work on reliably 4.1 and 4.5 ( at least almost always )  but don't work on a 4.3 phone ( one sample of each). I am using

ImageMagick to resize some png images as I have done routinely now to make 45x45 icons

that load with the app and seem to work fine on all phones tested. However, code like


Bitmap regIcon =  Bitmap.getBitmapResource("a.png");
Bitmap icon =Bitmap.getBitmapResource("b.png");


fails on the 4.3 phone and just leaves the static original icon on the ribbon.


However, I can get this to work for creating solid color icons that respond to roll over just fine,


public static Bitmap findx(String nm, int color)

        Bitmap b= Bitmap.getBitmapResource(nm);
        if (b==null)
            b = new Bitmap(45,45);
            Graphics g= new Graphics(b);
        return b;


Now, admittedly I'm using some kluged code to set the icons ( see below ) but the problem seems

to be an inability to actually find an image since the getBitmapResource apparently

returns null ( but again just on the 4.3 phone, possibly intermittently on 4.5 but rarely if ever).  

However, earlier it seemed to be

setting one of the icons but not the other on 4.3( with the same images).  I'm

just adding the images to the rapc command line and not including any special processing

options. This also seemed to work completely until I started building on a new machine but all

the other builds and features appear to work ( are there any specific problems with

some 4.3 compilers? The same build for 4.3 however runs fine on a 4.5 phone ).



public static void spamIcons(Bitmap b, Bitmap c, boolean foo, boolean bar)
             if (foo) HomeScreen.updateIcon(b);
            if (bar) HomeScreen.setRolloverIcon(c);
           } catch (Exception e) {}
           for (int i=0; i<3; ++i)
               try {
                 if (foo) HomeScreen.updateIcon(b,i);
                if (bar) HomeScreen.setRolloverIcon(c,i);
               } catch (Exception e) {}




I guess it may also be worth noting that this is occuring at startup. Is there a situation

where the resources may not be observable after this sequence ?


ApplicationManager myApp = ApplicationManager.getApplicationManager();
while (myApp.inStartup()){ try {  Thread.sleep(2000); } catch (Exception ex){} }

Note that I am holding the event lock continuously during this wait for startup and the

bitmap load and icon set process. 







Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: What limts on find a resource at startup and use image to set as an icon using HomeScreen?

I played around with this a little and think there could have been a couple

of issues but not sure what is going on. First, it seems to behave repeatably if I move

the wait for start up out of the UI thread ( not run with invokelater ) and then load the icons

with a follow-up invokelater. I'm not sure I understand why you want to sleep in

code called from invokelater as this seem to stall everything but I'm not sure I understand

the startup situation too well either. 



It also seems that a clean install, while it does start the "alternative autostart entry point"

since it initiates SMS listeners invoked at same time, it doesn't seem to

set the new rollover icon until a reboot, even if no reboot was  required for the install.


So, I'm still not sure I understand the case where I can get a rollover icon but need to use

failover bitmaps due to an inability to load the images specified, but at least I now seem

to have a workable situation ( the rollover won't start on initial load until user runs the app,

but that is ok at least for now).