Symbian
Symbian OS Library

FAQ-0760 When displaying graphics in an app, there is a long delay the first time the graphic is displayed. Is it possible to pre-load the images?

[Index][spacer] [Previous] [Next]



 

Classification: Java Category: AWT
Created: 01/07/2002 Modified: 01/17/2002
Number: FAQ-0760
Platform: Symbian OS v6.0

Question:
When displaying graphics in an application running on the Nokia 9210, there is a long delay the first time the graphic is displayed to the screen whilst the image(s) is (are) loaded. Is it possible to pre-load the image(s) on a background thread rather than waiting until the first time an attempt is made to display it?

Answer:
Yes. Use the waitForAll() method of the java.awt.MediaTracker class. This loads all the images being tracked by the MediaTracker object. This could be done in a background thread as soon as the application is launched.
MediaTracker tracker = new MediaTracker(this);
URL urlForImageFile = getClass().getResource("Resources/firstImage.gif");
image1 = getToolkit().getImage(urlForImageFile);
urlForImageFile = getClass().getResource("Resources/secondImage.gif");
image2 = getToolkit().getImage(urlForImageFile);
tracker.addImage(image1, 0);
tracker.addImage(image2, 0);

try
{
tracker.waitForAll();
}
catch(InterruptedException ioe)
{
}



    Now the images are already loaded the first time the graphic is displayed.