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
Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified
Accepted Solution

AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Done

Now that I've fixed the app I'm working on so that it does not run on the event thread...I'm back at addressing the AnimatedGIF screen issue I'm having.

 

Here's the code I'm using:

 

 

    progressScreen(String s)
    {
        super(new HorizontalFieldManager(), Field.FOCUSABLE);
        agf = new AnimatedGIFField(((GIFEncodedImage)GIFEncodedImage.getEncodedImageResource("resources/ajaxloader.bin")), Field.FIELD_LEFT);
        lbl = new LabelField(s, Field.FIELD_RIGHT);
        hfm.add(agf);
        hfm.add(lbl);
        add(hfm);
    }
// behavior when displaying screen

    // method for displaying screen
    public void show()
    {
        UiApplication.getUiApplication().pushScreen(this);
    }
    // method for dismissing screen
    public void close()
    {
        UiApplication.getUiApplication().popScreen(this);
    }

 

 

If I call the show() method at the start of my background task and don't close it, the screen appears AFTER the Dialog.alert("success") displayed to the user from the non-event thread, and stays on the screen until I close the simulator.

 

If I call the show() method at the start of the background task, then the close() method at the end of the task, the screen never displays on the simulator.  I tested on my Blackberry, because I thought it might not have time to display because networking runs quickly in the simulator, but the screen doesn't display there either.

 

If I eliminate the custom progresscreen I  built and use a simple Status.show for the progress screen instead, it displays correctly.

 

I'm going to compare my progressScreen against Status.show to see if I notice anything...but if anyone has any ideas as to why this isn't working, I'd love to hear them.  And thanks in advance.

Developer
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

[ Edited ]

Hi, 

The code seems to be pretty straight.. It should work. 

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

The '.bin' is used because otherwise the gif will be converted to a png.  I use '.agif' as the suffix of my animated gifs for the same reason. 

 

Can I suggest that you try this processing from menu items first off to make sure the screen is working correctly.  So have one menu item that calls show and another than calls close on the same Screen you have defined.

 

Once you have got that working, then we can look at whether we have another Event Thread type conflict going on with the push.

 

You have the network Thread running off the Event Thread, but do you have something else 'waiting' on the Event Thread?  We can look at this later.

 

With respect to the network time in the SImulator, I would suggest you add lines like the following to your network Thread to slow down your networking on the Simulator.

 

If (DeviceInfo.isSimulator() ) {

try {

Thread.sleep(10000);

} catch (Exception e) {}

}

Developer
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

[ Edited ]

Ya i guess the event thread is being held up by the screen. This is when pushscreen is used. I tried the same by using the deprecated method pushGlobalScreen(screen,int,bool) . It got displayed , and it also let the event thread continue. But when i tried popScreen on this , it threw an exception saying cannot mix queuestatus-dismissstatus with pushGlobalScreen-popScreen..

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

 


peter_strange wrote:

The '.bin' is used because otherwise the gif will be converted to a png.  I use '.agif' as the suffix of my animated gifs for the same reason. 

 



 

 

That is an excellent idea...mind if I borrow that?  Keeps the 'gif' part so I know it's a gif, but keeps RIM from converting it to a png.

 

 


peter_strange wrote:

Can I suggest that you try this processing from menu items first off to make sure the screen is working correctly.  So have one menu item that calls show and another than calls close on the same Screen you have defined.

 

Once you have got that working, then we can look at whether we have another Event Thread type conflict going on with the push.

 



 

 

I can try that...only thing is that I'd have to add the menuitems to the browser...the only other screens in my application is a dialog prompting for credentials and the progress screens (which we're working on).  I'll start on the code...post again if the menu items being in the browser would affect the test you outlined above

 

 


peter_strange wrote:

 

You have the network Thread running off the Event Thread, but do you have something else 'waiting' on the Event Thread?  We can look at this later.

 



 


 

not sure...I'll take a look at that. Pretty much everything that is running in my app is off the Event Thread...I have to use a bunch of UiApplication.getUiApplication().invokeLater(Runnable r) calls to make sure that the credentials screen and the Dialog.alert()s show up.

 

Just in case, here's the code for main()

 

 

public class addToReadingList extends UiApplication
{
     addToReadingList()
    {
           browserMenuItem bmi = new browserMenuItem(10);
           ApplicationMenuItemRepository repository = ApplicationMenuItemRepository.getInstance();
           repository.addMenuItem(ApplicationMenuItemRepository.MENUITEM_BROWSER, bmi);
           // hide app from the Application Switcher
           setAcceptsForeground(false);
    }
    
      /**
     * @param args the command line arguments
     */

    public static void main(String[] args)
    {
           addToReadingList atrl = new addToReadingList();
           atrl.enterEventDispatcher();
    }
    private boolean _acceptsForeground;

 //This is the method to override
    protected boolean acceptsForeground() {
        return _acceptsForeground;
    }
    //This method sets whether the application will allow itself
    //to foreground
    protected void setAcceptsForeground(boolean bool)
    {
        _acceptsForeground = bool;
    }
    }

 

Here's the ApplicationMenuItem.run() part of the code that's set up by main()

 

 

 public Object run(Object context)
    {
        try
        {
        if (context != null)
        {
                threadReadItLater tril = new threadReadItLater(context);
                Thread t = new Thread(tril);
                t.start();
        }
        }catch(Exception ex)
        {
            //System.out.println("Handling context error code: " + ex.toString());
        }
        return null;
      }

 

 

 

 

 

 

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

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

"only thing is that I'd have to add the menuitems to the browser..."

 

Sorry I forgot that.  I suggest you create a 'test' application, with a single MainScreen, and add the push as a menu item on that.  In reflection that is going to make the close difficult.  Hm... 

 

basically I sSuggest you create something so that you can test your animated gif Field in a simpler, more standard, environment before trying to hook it into your menu processing. 

 

Finally feel free to use the .agif suffix.  That will be a beer you owe me mind!

Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

 


peter_strange wrote:

"only thing is that I'd have to add the menuitems to the browser..."

 

Sorry I forgot that.  I suggest you create a 'test' application, with a single MainScreen, and add the push as a menu item on that.  In reflection that is going to make the close difficult.  Hm... 

 

basically I sSuggest you create something so that you can test your animated gif Field in a simpler, more standard, environment before trying to hook it into your menu processing. 

 

Finally feel free to use the .agif suffix.  That will be a beer you owe me mind!


 

 

Hmmm.  The run() method in the ApplicationMenuItem is short...I can temporarily comment that out and replace it with something that will display the screen...

 

Actually, I just caught something.  you said

 

 


peter_strange wrote:

 

basically I sSuggest you create something so that you can test your animated gif Field in a simpler, more standard, environment before trying to hook it into your menu processing. 

 


 

 

The animated GIF is working actually.  I'm just having a problem with the actual progressScreen that it is on. 

The progressScreen with the animated GIF will show up if I just call progressScreen.show().  If I call progressScreen.show() before the background task starts, then progressScreen.close() after it stops, it never displays at all.  Even on the device, where the network task takes some time and it should display (if the problem lies with the simulator network being too fast) it doesn't.

 

Should I still try displaying it in a more conventional environment?

 

(and I'll make a note about that beer!)

Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

Okay, here's the next puzzle:

 

If I use UiApplication.getUiApplication.pushModalScreen(animatedProgressScreen), it behaves like the Status.show did and shows the animated progress screen.

 

Unfortunately I can't do that, as I want the background thread to run behind the progress screen...and it won't do that if I push it as a modalScreen.

 

Argh!  So close!

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

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

Sorry to say (and I know we have been round this before) this does suggest to me that you are not releasing the Event Thread.

 

To test this, can you do the following:

 

a) In your code that you think runs off the Event Thread, can you add the following:

 

if ( Application.getApplication().isEventThread() ) {

Status.show("Running on Event Thread");

}

 

b) Can you replace

UiApplication.getUiApplication.pushModalScreen(animatedProgressScreen),

with the following code (two sets of code for two attempts), and let us know whether the screen is displayed at the correct time.

 

b.1) First

UiApplication.getAuiApplication(invokeLater(new Runnable() {

public void run() {

UiApplication.getUiApplication.pushScreen(animatedProgressScreen),

}

});

 

b.2) Second

UiApplication.getAuiApplication(invokeAndWait(new Runnable() {

public void run() {

UiApplication.getUiApplication.pushScreen(animatedProgressScreen),

}

});

Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

 


peter_strange wrote:

Sorry to say (and I know we have been round this before) this does suggest to me that you are not releasing the Event Thread.

 

To test this, can you do the following:

 

a) In your code that you think runs off the Event Thread, can you add the following:

 

if ( Application.getApplication().isEventThread() ) {

Status.show("Running on Event Thread");

}

 

b) Can you replace

UiApplication.getUiApplication.pushModalScreen(animatedProgressScreen),

with the following code (two sets of code for two attempts), and let us know whether the screen is displayed at the correct time.

 

b.1) First

UiApplication.getAuiApplication(invokeLater(new Runnable() {

public void run() {

UiApplication.getUiApplication.pushScreen(animatedProgressScreen),

}

});

 

b.2) Second

UiApplication.getAuiApplication(invokeAndWait(new Runnable() {

public void run() {

UiApplication.getUiApplication.pushScreen(animatedProgressScreen),

}

});


 

No need to apologize.  Those are excellent suggestions...I will do so and post back.