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: 86
Registered: ‎01-20-2012
My Device: Bold Touch

Re: How to display images on the main screen UI from a background thread

Hi I just tried it on my current simulator it just displays a red colour rectangle and thats it. Nothing else happens

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

Re: How to display images on the main screen UI from a background thread

Try it in some others.  Certainly try it in some OS 7.0 SImualtors. 

 

Is the red rectangle what you expected?

New Developer
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch

Re: How to display images on the main screen UI from a background thread

Hi peter,

 

I tested on two other 7.0 OS simulators and it is still the same. Only a red colour rectangle is displayed.

New Developer
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch

Re: How to display images on the main screen UI from a background thread

do you think its an OS bug?

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

Re: How to display images on the main screen UI from a background thread

Not sure.  Can you test on anything other than OS 7.

 

By the way, I hope you tried the menu to change it?

New Developer
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch

Re: How to display images on the main screen UI from a background thread

[ Edited ]

Il keep trying on others as well. what do you mean by "I hope you tried the menu to change it?"

 

by the way i had done setBitmap using 2 static images to see whether setBitmap works and it did work that  time. If you had read the other thread i had posted before. and I tried doing it in a background thread and it worked perfect fine. but it doesnt work with this one and hte bitmap doesnt get updated. even if i just put 2 static images in my app to test it would update

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

Re: How to display images on the main screen UI from a background thread

OK, my mistake.  Can you put the code back to the way it was (my original post above). and add the following lines before you add bmf:

 

        Background blueBackground = BackgroundFactory.createSolidBackground(0x000080);
        bmf.setBackground(blueBackground);

 

The problem is that the supplied bitmaps expect to blend into a dark background, you won't see them on a white background.

 

Tell me what you see now.

 

By menu, press the Menu button and select the "Bitmap" menu item to change the actual bitmap displayed. 

New Developer
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch

Re: How to display images on the main screen UI from a background thread

[ Edited ]

Hi peter,

 

I tried it and it worked. the blue square was behind the red square and when i selected bitmap from the menu options it kept on changing from question mark to exclamation mark.

 

I did a similar thing using a button to update the main Screen  and as well as using a background thread(using 2 static images) and it worked perfectly fine. But i dont understand why its not working in this case. Ive been stuck at this point for 2 weeks now.

 

For your reference this is what i did with the static images and this is similar to the design of my app. In my app when i press the signIn and if its successful it will start streaming images in a loop from a background thread.

 

cheers

 

public final class MyScreen extends MainScreen
{
    /**
     * Creates a new MyScreen object
     */
    public Bitmap bmp;
    public BitmapField bmpField;
    public ButtonField btnDisplay;
    public ImageThread imgThread;
    
    public MyScreen()
    {        
        // Set the displayed title of the screen       
        setTitle("MyTitle");
        bmp = Bitmap.getBitmapResource("image.png");
        btnDisplay = new ButtonField("Display");
        bmpField = new BitmapField(bmp);       

        
        
        btnDisplay.setChangeListener(new FieldChangeListener() {
            
            public void fieldChanged(Field field, int context) {
                // TODO Auto-generated method stub
                
                if(field == btnDisplay)
                {
//                    bmp = Bitmap.getBitmapResource("image1.png");
//                    bmpField.setBitmap(bmp);
                    LaunchImageThread();
                }                
            }
        });
        
        add(bmpField);
        add(btnDisplay);
        
    }
    
    private void LaunchImageThread()
    {
        imgThread = new ImageThread(this);
        new Thread(imgThread).start();
    }   
}

 

//////////////////////////////////////////////////////////////////////

 

public class ImageThread implements Runnable
{
    MyScreen parent;
    
    public ImageThread(MyScreen myScreen)
    {
        parent = myScreen;
    }

    public void run()
    {                
        try
        {
            UiApplication.getUiApplication().invokeLater(new Runnable() {
                
                public void run() {
                    // TODO Auto-generated method stub
                    parent.bmp = Bitmap.getBitmapResource("image1.png");
                    parent.bmpField.setBitmap(parent.bmp);
                    
                }
            });                                
        }
        catch(Exception ex)
        {
            System.out.println("Exception in Thread: " + ex.getMessage());
        }
        
    }
    
}

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

Re: How to display images on the main screen UI from a background thread

OK, tell you where I think we are now.

 

1) We have proved that the background Thread does correctly use setBitmap, but the setBitmap() does not result in a layout() or a paint(), so this Screen is clearly not on show.

2) We have proved that setBitmap does actually update the Screen if it is displayed.

3) We have shown that the camView that is being updated is NOT the active Screen.

 

Given this, I suspect you have created another camView screen and this is the one on display.  However your Background Thread was started with a different camView screen. 

 

We can easily test this.

 

You might remember previously I had asked to override the setBitmap() of the Field being updated.  You did that to prove the setBitmap was being called.

 

We can use code in this setBitmap() to bring that Screen to the front.

 

The code required is relatively simple.

 

Screen s = this.getScreen();

if ( s != UiApplication.getUiApplication.getActiveScreen() ) {

if ( s.isDisplayed()() ) {

UiApplication.getUiApplication.popScreen(this);

}

UiApplication.getUiApplication.pushScreen(this);

}

 

I would put this code at the start of the setBitmap() override, and put a break point on it.  Then try the processing and step through the code. 

 

Let us know what you find. 

New Developer
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch

Re: How to display images on the main screen UI from a background thread

Hi Peter,

 

what you mean by overriding setBitmap is where we created a customized BitmapField? Il try and let you know