问题描述
我的应用程序中包含大量的图像。所以它需要一些时间来加载该应用程序。我想显示加载屏幕whhile应用程序被加载。这怎么可能?
My application contains lots of images. so it takes some time to load the application. I want to show a loading screen whhile the application is being loaded. How is it possible ?
推荐答案
下面是一个例子应用程序,骷髅你的希望做。基本上,你推初始画面是一个载入画面。在最初的启动顺序,你需要旋转了一个新的线程,做你装的东西,然后使用的invokeLater:1)确保您在事件调度员和2)推一个新的屏幕 - 或者在这个例子中的情况下,对话框 - 屏幕让用户从进度加载屏幕上移开
Here's an example app that skeletons what your looking to do. Basically, the initial screen you push is a loading screen. During the initial startup sequence you need to spin up a new thread, do your loading stuff and then use invokeLater to 1) make sure your in the event dispatcher and 2) to push a new screen -- or in the case of this example a dialog -- to the screen to have the user progress away from the loading screen.
这里的code:
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
/**
* Just a test app.
*/
public class TestAppMain extends UiApplication
{
/**
* Default Constructor.
*/
private TestAppMain() {
pushScreen(new AppScreen(this));
}
/**
* App entry point.
* @param args Arguments.
*/
public static void main(String[] args) {
TestAppMain app = new TestAppMain();
app.enterEventDispatcher();
}
/**
* Main application screen.
*/
private static class AppScreen extends MainScreen
{
UiApplication _app;
/**
* Default constructor.
*/
public AppScreen(UiApplication app) {
// Note: This screen just says "Loading...", but you could
// add a loading animation.
_app = app;
LabelField title = new LabelField("App Name",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
LabelField loading = new LabelField("Loading...",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
add(loading);
// Queue up the loading process.
startLoading();
}
/**
* Create the loading thread. Make sure to invoke later as you will
* need to push a screen or show a dialog after the loading is complete, eventhough
* you are creating the thread before the app is in the event dispatcher.
*/
public void startLoading() {
Thread loadThread = new Thread() {
public void run() {
// Make sure to invokeLater to avoid problems with the event thread.
try{
// Simulate loading time
Thread.sleep(5000);
} catch(java.lang.InterruptedException e){}
// TODO - Add loading logic here.
_app.invokeLater( new Runnable() {
public void run() {
// This represents the next step after loading. This just shows
// a dialog, but you could push the applications main menu screen.
Dialog.alert("Load Complete");
}
});
}
};
loadThread.start();
}
}
}
这篇关于黑莓 - 应用程序的载入画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!