わかりました、私はこのセットアップを手に入れました:ミドル
Gui extends Midlet{
private static Gui instance;
protected void startApp() {
Display.getDisplay(this).setCurrent(MyForm.getInstance());
}
private static final Logger log = LoggerFactory.getLogger();
public static Datacheck getInstance() {
return instance;
}
public Gui() {
// Configure logging
}
protected void startApp() {
instance = this;
Display.getDisplay(this).setCurrent(MyForm.getInstance());
}
protected void pauseApp() {
}
protected void destroyApp(boolean bool) {
// Shutdown Microlog gracefully
LoggerFactory.shutdown();
notifyDestroyed();
}
public static void log(Level level, String message) {
log.log(level, message);
}
public void requestScreen(Form screen) {
log.info("request screen called");
Display.getDisplay(this).setCurrent(screen);
}
}
フォーム
MyForm extends Form{
private static MyForm instance;
public static MyForm getInstance() {
if (instance == null) {
instance = new MyForm();
}
return instance;
}
private Form(){
//start task
new Timer().scheduleAtFixedRate(new PollingService(CallsDialog.getInstance()), 0, UPDATE_INTERVAL);
//add gui elements ....
}
private void updateForm() {
//never gets executed
}
}
とスレッド
MyThread implements Runnable{
private MyForm handle;
public PollingService(MyForm handle) {
this.handle = handle;
}
public void run() {
handle.updateForm();
}
}
したがって、ミッドレットが開始し、そのフォームをMyFormのインスタンスに設定してから、myformが新しいスレッドを作成します。このスレッドは5秒ごとにmyformの関数を呼び出す必要があります。
これは実物の非常に単純化された例ですので、スレッドのデザインを変更しないでください
「MyForm」クラスからメソッドを実行しても実行されないので、エラーは発生しません。
誰かが私が間違っていることを知っていますか?
編集 が変更されたため、スレッドは作成されません(timertaskによってすでに実行されています)