Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
nordavinder
Posts: 23
Registered: ‎12-02-2012
My Device: BlackBerry 8300
Accepted Solution

How to close this blocking modal dialog and open another after a few minutes

This is my method for displaying a modal dialog:

 

public static Dialog handleInactivityDialog(String msg, int[] values) {
     Dialog dialogo = new Dialog(msg, new String[] {"Yes", "No"}, values, 2, null);
     int i = dialogo.doModal();
     if (i == 1){
         try{
               //do something
               Utils.popScreenForLogout();
          }catch(Exception e){
               Utils.forceLogout();
          }
      }
      return dialogo;

}

 

After 3 minutes, that dialog must be closed and a new one should be opened. The new dialog should be closed after 1 minute.

 

I have no idea on how to do this since DIalog.doModal() is a blocking operation.

 

Thanks in advance!

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to close this blocking modal dialog and open another after a few minutes

you can start a timertask before you call doModal, for example.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
nordavinder
Posts: 23
Registered: ‎12-02-2012
My Device: BlackBerry 8300

Re: How to close this blocking modal dialog and open another after a few minutes

Thanks Simon, I have read this answer:

 

http://stackoverflow.com/a/4348675/1293724

 

but I don't know how to adapt my code to that suggestion.

 

 

Contributor
nordavinder
Posts: 23
Registered: ‎12-02-2012
My Device: BlackBerry 8300

Re: How to close this blocking modal dialog and open another after a few minutes

public static void handleInactivityDialog(String msg, int[] values) {
         final Dialog dialogo = new Dialog(msg, new String[] {"Sí", "No"}, values, 2, null);
         Timer timer = new Timer();
         timer.schedule(new TimerTask(){

         public void run()
         {    
               synchronized (UiApplication.getEventLock()) {
                      int i = dialogo.doModal();
                      if (i == 1){
                            try{
                                   //do something
                                   Utils.popScreenForLogout();
                            }catch(Exception e){
                            Utils.forceLogout();
                            }
                      }
               }
          }

           }, 60*1000);

}

 

In case this is fine, where should I add the dialog.close() ?

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to close this blocking modal dialog and open another after a few minutes

the timertask would have the purpose the close the dialog, not to display it.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
nordavinder
Posts: 23
Registered: ‎12-02-2012
My Device: BlackBerry 8300

Re: How to close this blocking modal dialog and open another after a few minutes

Ok, thanks Simon. This way works:

 

public static void handleInactivityDialog(String msg, int[] values) {
       final Dialog dialogo = new Dialog(msg, new String[] {"Sí", "No"}, values, 2, null);
       Timer timer = new Timer();
       timer.schedule(new TimerTask(){

                public void run()
                {
                   synchronized (UiApplication.getEventLock()) {
                               dialogo.close();
                   }

               }

      }, 60*1000);
     int i = dialogo.doModal();
     if (i == 1){
        try{
             CommManager.doLogout();
             Utils.popScreenForLogout();
         }catch(Exception e){
            Utils.forceLogout();
         }
     }  

}