2012-04-26 2 views
1

안녕하세요, 모두 백그라운드 응용 프로그램에서 화면을 전역으로 푸시 할 때 제어하고 싶습니다. 현재 나는 메인 스크린을 확장하고있는 스크린을 만들었다. 나는이 화면을 세계적으로 보여주고 싶다. 나는 두 화면이 차례로 표시되면 pushGlobalScreen(Screen to push, int priority, flag); 작업을 사용하고 있습니다. 그러나 내가 실제로하고 싶은 것은 있습니다. 첫 화면을 닫고 다음 화면을 보여주고 싶습니다. 그래서 이것을 달성하는 방법. 여기백그라운드 프로세스에서 화면을 전역 적으로 제어하는 ​​방법

좀 더 명확하게 설명하고

나는 현재 시간이 다음 알람 시간과 일치하는 경우 나 시간에 대한 데이터베이스에서 확인하고 전체 시나리오를 설명하고 그것을 밀어 화면이 둘 이상있는 가정하자 알람은 같은 시간 동안 저장됩니다.

while (Checking into database for time){ 
if (databasetime == current time) {// let suppose there is more than 
            //one alarm save for the same time 
    synchronized (getEventLock()) {// This will call one after other but i want to first 

     UiEngine ui = Ui.getUiEngine(); 

     ui.pushGlobalScreen(new AlarmScreen() , 1, UiEngine.GLOBAL_QUEUE);// 
         //Here i want to stop. I want user to close the screen then 
         // i want to push again the screen. As we do in 
         // PushModalScreen(Screen) How can i block 
        //pushGlobalScreen(new AlarmScreen() , 1, UiEngine.GLOBAL_QUEUE); 
     } 

    } 

} 

내 요구 사항이 분명하다고 생각합니다. 그렇지?

+0

내가 알고있는 점은 디스플레이 스택에 두 개 이상의 'AlarmScreen' 인스턴스를 밀어 넣지 않으려한다는 것입니다. – Rupak

+0

네, 맞습니다. 첫 번째 질문을 닫은 후 두 번째 화면을 푸시하고 싶습니다. – BBdev

+0

코드 스 니펫을 게시했는지 확인하십시오. – Rupak

답변

0

나는이 문제를 해결하지만 다른 방법으로했다. 내가 선택한 방법은 테이블에 모든 ID를 저장하고 테이블에 ID가 있는지 확인하는 것입니다. 단 하나의 화면 만 푸시합니다. 그리고 그 테이블을 닫을 전에 더 많은 ID가 있는지 그냥 확인하고 있습니다. updating the Contents of the Screen. 이제는 내가 원하는 방식으로 작동하고 더 이상 데이터가없는 경우 화면을 닫을뿐입니다.

2

AlarmScreen 인스턴스를 푸시하기 전에 표시 스택에서 AlarmScreen 인스턴스를 제거하는 코드 스 니펫을 확인하십시오. 애플리케이션 (UiApplication)는 다음

net.rim.device.api.ui.Screen currentScreen = Ui.getUiEngine().getActiveScreen(); 

// pop previously pushed AlarmScreen 
if (currentScreen instanceof AlarmScreen) { 
    try { 
     Ui.getUiEngine().popScreen(currentScreen); 
    } catch (IllegalArgumentException iaexc) { 
     // If your screen is not on the stack. 
    } catch (Exception exc) {   
    } 
} 

// push new AlarmScreen 
synchronized (Application.getEventLock()) { 
    Ui.getUiEngine().pushGlobalScreen(new AlarmScreen() , 1, UiEngine.GLOBAL_QUEUE); 
} 




AlarmScreen의 큐를 이용한다. 디스플레이 스택에서 활성 AlarmScreen이 제거되면 대기열에있는 다른 AlarmScreen을 디스플레이 스택으로 푸시합니다.

package mypackage; 

import net.rim.device.api.ui.UiApplication; 
import net.rim.device.api.ui.container.MainScreen; 

public class MyApp extends UiApplication implements CloseEventListener { 
    public static void main(String[] args) { 
     (new MyApp()).enterEventDispatcher(); 
    } 

    private AlarmScreen []queue; 
    private int MAX = 10; 
    private int head = 0; 

    public MyApp() { 
     // initialize queue 
     queue = new AlarmScreen[MAX]; 
     head = 0; 
     for (int i=0;i<MAX;i++) { 
      queue[i] = new AlarmScreen(this, "Screen no. " + i); 
     } 

     // push first screen on display 
     UiApplication.getUiApplication().pushScreen(queue[head ++]); 
    } 

    public void screenClosed() { 
     if (head < MAX) { 
      UiApplication.getUiApplication().pushScreen(queue[head ++]); 
     } 
    } 
} 

interface CloseEventListener { 
    public void screenClosed(); 
} 

class AlarmScreen extends MainScreen { 
    private CloseEventListener listener; 

    public AlarmScreen(CloseEventListener listener, String title) { 
     setTitle(title); 
     this.listener = listener; 
    } 

    public boolean onClose() { 
     try { 
      UiApplication.getUiApplication().invokeLater(new Runnable() { 
       public void run() { 
        close(); 
       } 
      }); 
     } catch (Exception exc) { 
      System.out.println(exc.getMessage()); 
     } 
     // push a new screen from waiting queue 
     if (listener != null) { 
      listener.screenClosed(); 
     } 
     return true; 
    } 
} 
+0

실제로이 방법으로이를 수행하고 싶지는 않습니다. 사용자가 화면을 닫고 새 AlarmScreen()을 누르기를 원합니다. 즉, 디스플레이 스택에 하나의 화면이있는 경우 코드 pushGlobalScreen이 두 번 실행되어서는 안됩니다. 현재 스택에 화면이 없을 때까지 대기합니다. 코드 스 니펫을 보내 주셔서 감사합니다. – BBdev

+0

그러면 모든 'AlarmScreen' 인스턴스를 포함하는 대기열을 유지 관리 할 수 ​​있습니다. 그리고 사용자가 활성'AlarmScreen'을 닫을 때 큐의 첫 번째 요소를 누르십시오 (비어 있지 않은 경우). 구현에 대한 도움이 필요하면 힌트를 줄 수 있습니다. – Rupak

+0

그래, 도움이된다면 도움을 줄 수있다. :) – BBdev

관련 문제