リチャードが彼の回答で述べたように、メイン(別名「UI」)スレッド以外のスレッドからUIを操作しようとしているため、問題が発生しています。コードを正しく機能させるには、小さな変更が必要です。
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
pushScreen(new MyScreen());
}
},
200 /* delay */,
false /* repeat = no */);
上記は、BlackBerryJava用に投稿したコードに相当します。
私の目標は、SplashScreenを10秒間押すことです。そうすると、MyScreenページが開きます。そのため、MyScreenページを開いている間はタイマーを10秒間使用したいと思います。タイマーの間、SplashScreenページを表示します。
これが実際にやりたいことである場合はSplashScreen
、アプリが起動したらすぐに表示されるようにします。
public class MyApp extends UiApplication
{
/**
* Entry point for application
* @param args Command line arguments (not used)
*/
public static void main(String[] args)
{
// Create a new instance of the application and make the currently
// running thread the application's event dispatch thread.
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
public MyApp()
{
// Push a screen onto the UI stack for rendering.
final SplashScreen splashScreen = new SplashScreen();
pushScreen(splashScreen);
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
pushScreen(new MyScreen());
popScreen(splashScreen);
}
},
10*1000 /* delay in msec */,
false /* repeat = no */);
}
これはあなたが求めたことを実行しますが、Richardが提供するリンクにより、ユーザーはスプラッシュ画面を早期に閉じることもできます。それはあなたが望むものかもしれないし、そうでないかもしれないので、私は単に上記の代替案を提供します。