2014-02-05 2 views
0

idd 시간이 4 분 이상이면 메시지 대화 상자 을 표시해야합니다. 유휴 시간이 5 분 이상인 경우 첫 번째 대화 상자를 닫고 5 초 후에 자동으로 대화 상자를 닫아야합니다. 내 코드와글로벌 대화 상자를 닫고 BlackBerry에서 다른 대화 상자를 표시하는 방법?

public static RealtimeClockListener clockListenerTest = new RealtimeClockListener() { 
       public void clockUpdated() { 
         int _4Minutes = 60 * 4; 
         int _5Minutes = 60 * 5; 
         Dialog dialog4Minutes = new Dialog("Stay Logged In?", new String[] {"SI", "NO"}, new int[]{1,2}, 2, null); 
         dialog4Minutes.setDialogClosedListener(new DialogClosedListener() { 
           public void dialogClosed(Dialog dialog, int choice) { 
            //TODO 
           } 
         }); 
         Dialog dialog5Minutes = new Dialog("You will be disconnected", new String[] {"OK"}, new int[]{1}, 1, null); 
         dialog5Minutes.setDialogClosedListener(new DialogClosedListener() { 
           public void dialogClosed(Dialog dialog, int choice) { 
            //TODO 
           } 
         }); 
         synchronized (UiApplication.getEventLock()) { 
           UiEngine ui = Ui.getUiEngine(); 
           if(DeviceInfo.getIdleTime()>=_4Minutes && DeviceInfo.getIdleTime() < _5Minutes){ 
             ui.pushGlobalScreen(dialog4Minutes, 1,UiEngine.GLOBAL_QUEUE); 
           }else if(DeviceInfo.getIdleTime()>=_5Minutes){ 
             dialog4Minutes.close(); 
             ui.pushGlobalScreen(dialog5Minutes, 1,UiEngine.GLOBAL_QUEUE); 
           } 
         } 
       } 
     }; 

문제가 첫 번째 대화가 수동으로 닫을 때까지 첫 번째 대화는 다른 절에 폐쇄되지 않습니다 및 두 번째 대화 상자가 표시되지 않는 것입니다 :

내가 지금까지 무엇을 가지고 .

else 절의 코드를 제대로 작동 시키려면 어떻게해야합니까? 그리고 5 초 후에 두 번째 대화 상자를 닫아야합니까? 나는 그 타이머를 생각하고 있었는데, 하지만 이것이 최선의 방법인지는 모르겠다.

미리 감사드립니다.

답변

1

귀하의 코드에 간단한 코딩 오류가 있다고 생각합니다. 귀하의 문제에 기여할 수 있습니다. clockUpdated()를 실행할 때마다 새로운 dialog4Minutes를 만듭니다. 따라서 닫을 때 dialog4Minutes.close()를 사용하면 방금 생성 한 대화 상자가 닫히고 표시되는 대화 상자는 닫히지 않습니다. 내가 clockUpdated 실행 생각하기 때문에

public static RealtimeClockListener clockListenerTest = new RealtimeClockListener() { 
    int _4Minutes = 60 * 4; 
    int _5Minutes = 60 * 5; 
    Dialog dialog4Minutes = null; 
    Dialog dialog5Minutes = null; 
    public void clockUpdated() { 
     synchronized (UiApplication.getEventLock()) { 
      UiEngine ui = Ui.getUiEngine(); 
      if (DeviceInfo.getIdleTime() < _4Minutes){ 
       // Shouldn't be needed - this is just for safety 
       if (dialog4Minutes != null) { 
        dialog4Minutes.close(); 
        dialog4Minutes = null; 
       } 
      } 
      if (DeviceInfo.getIdleTime() < _5Minutes){ 
       // Shouldn't be needed - this is just for safety 
       if (dialog5Minutes != null) { 
        dialog5Minutes.close(); 
        dialog5Minutes = null; 
       } 
      } 
      if (DeviceInfo.getIdleTime() >= _4Minutes && DeviceInfo.getIdleTime() < _5Minutes) { 
       if (dialog4Minutes == null) { 
        // 4 minute Dialog has not been pushed yet 
        dialog4Minutes = new Dialog("Stay Logged In?", new String[] {"SI", "NO"}, new int[]{1,2}, 2, null); 
        ui.pushGlobalScreen(dialog4Minutes, 1,UiEngine.GLOBAL_QUEUE); 
       } 
      } else if (DeviceInfo.getIdleTime()>=_5Minutes) { 
       if (dialog5Minutes == null) { 
        // 5 minute Dialog has not been pushed yet 
        dialog5Minutes = new Dialog("You will be disconnected", new String[] {"OK"}, new int[]{1}, 1, null); 
        ui.pushGlobalScreen(dialog5Minutes, 1,UiEngine.GLOBAL_QUEUE); 
        if (dialog4Minutes != null) { 
         dialog4Minutes.close(); 
         dialog4Minutes = null; 
        } 
       } 
      } 
     } 
    } 
}; 

나는 "동기 (UiApplication.getEventLock은())"필요 확실하지 않다 : 여기에 내가 이런 짓을 했을까 방법을 나타내는 몇 가지 샘플 (안 컴파일, 테스트하지) 대체 코드입니다 이벤트 스레드에 있지만이 코드에서는 상처를 입지 않습니다.

다른 질문에 대해서는 5 초 후에 닫기를 처리하는 방법에 대해 Timer 클래스를 살펴보십시오. 사용자가 실제로 Dialog를 확인하면 액션을 취하기 위해 setDialogClosedListener (예제에서 무시한)를 코딩해야합니다.

+0

Peter에 감사드립니다. 나는 5 초 후에 타이머를 사용하여 5 초 후에 클로즈를 처리했다. 타이머 작업에서 invokeLater 내부의 대화 상자를 닫으려면 코드를 넣어야했습니다. 또한 invokeLater 내부의 TimerTask와 Timer를 취소했습니다. 내가 대기 중이던 다른 질문에서 일할 것이다. – Lucas

관련 문제