以下のコードを使用して、Blackberry アプリケーションで「お待ちください」ポップアップを作成しています。デバイスのバック プレスでそのポップアップ画面を削除したいのですが、表示時にポップアップを待ってください画面全体が完了するまでブロックされているため、これを行うことができません。スレッド操作の。
これが私のコードです:
public class PleaseWaitLoginPopupScreen extends PopupScreen {
//statics ------------------------------------------------------------------
private AnimatedGIFField _ourAnimation = null;
private LabelField _ourLabelField = null;
private static String pleaseWaitText="";
private static PleaseWaitLoginPopupScreen ref;
public static PleaseWaitLoginPopupScreen getInstance(){
if(ref!=null){
ref=new PleaseWaitLoginPopupScreen(Constant.PLEASE_WAIT_TEXT);
}
return ref;
}
public PleaseWaitLoginPopupScreen(String text) {
super(new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL | VerticalFieldManager.VERTICAL_SCROLLBAR));
GIFEncodedImage ourAnimation = (GIFEncodedImage) GIFEncodedImage.getEncodedImageResource("loader.gif");
_ourAnimation = new AnimatedGIFField(ourAnimation, Field.FIELD_HCENTER);
this.add(_ourAnimation);
_ourLabelField = new LabelField(text, Field.FIELD_HCENTER);
this.add(_ourLabelField);
}
public static void showScreenAndWait(final Runnable runThis, String text) {
pleaseWaitText=text;
final PleaseWaitLoginPopupScreen thisScreen = new PleaseWaitLoginPopupScreen(text);
Thread threadToRun = new Thread() {
public void run() {
// First, display this screen
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(thisScreen);
}
});
boolean exceptionFlag = false;
// Now run the code that must be executed in the Background
try {
runThis.run();
} catch (Throwable t) {
exceptionFlag = true;
t.printStackTrace();
//throw new RuntimeException("Exception detected while waiting: " + t.toString());
}finally{
// Now dismiss this screen
if(exceptionFlag){//IF EXCEPTION OCURES THAN THIS CODE WILL RUN TO STOP THE PLEASE WAIT POP TASK
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(thisScreen);
}
});
}
}
}
};
threadToRun.start();
}
public void dismissPopupScreen(){
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(PleaseWaitLoginPopupScreen.this);
}
});
/*synchronized (UiApplication.getEventLock()) {
UiApplication.getUiApplication().popScreen(PleaseWaitLoginPopupScreen.this);
}*/
}
}