Skip to main content

slider to show progress while form loads

4 replies [Last post]
sundayokpokor
Offline
Joined: 2012-02-20
Points: 0

My app suddenly freezes when i call a form to load. The form to be loaded is fetching data from the web and i want to show a slider in the first form to keep the app interactive at least but the slider does not show not until the very seconds that the next form is to load. here is the code that loads the second form

list.addActionListener(new ActionListener()
{
   public void actionPerformed(ActionEvent ae)
   {
      Contents selected = (Contents)list.getSelectedItem();
      String form = selected.getText();
      if(Display.getInstance().getCurrent() == f){
        ProgressWork progresswork = new ProgressWork(slider);
        CelebOverview celeboverview = new CelebOverview(this.mid);
        Display.getInstance().callSeriallyAndWait(progresswork);
        Display.getInstance().callSeriallyAndWait(celeboverview);
      }
  }
}

How can i make the first form to still be interactive(not freezing)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mixaz
Offline
Joined: 2009-09-04
Points: 0

callSerially() executes Runnable on EDT thread, so LWUIT can't work (process events on EDT thread) until you code finishes.
You probably should use invokeAndBlock() instead, and update UI with progress from your Runnable via callSerially() calls, since your Runnable runs not in EDT thread in invokeAndBlock case.

sundayokpokor
Offline
Joined: 2012-02-20
Points: 0

thanks for your reply mixaz, i did as you wrote:

 
  ProgressWork progresswork = new ProgressWork(slider);
  CelebOverview celeboverview = new CelebOverview(this.mid);
  Display.getInstance().callSerially(progresswork);
  Display.getInstance().invokeAndBlock(celeboverview);

but it's still not updating the slider components. The slider infinite property is set to true and is suppose to be visible as soon as the internet connection is made. I used a dialog instead with the message that will tell the user that something is happening.

mixaz
Offline
Joined: 2009-09-04
Points: 0

The code looks strange, I think that it is wrong. I would do something in this way (code is not exact, just a sample):

class ProgressWork extends Dialog {
    ...
    public setProgress(int progress) { ... }
}

class CelebOverview extends Form {
    ...
    public void actionPerformed(ActionEvent evt) {
        ...
        final ProgressWork progressDialog = new ProgressWork();
        progressDialog.show();
        Display.getInstance().invokeAndBock(new Runnable() {
            public void run() {
                ...
                final int progress = 50;
                Display.getInstance().callSerially(new Runnable() {
                     public void run() {
                         progressDialog.setProgress(progress);
                });
                ...
                // do the same if want to update progress dialog with new value - call
                // setProgress() via callSerially() with new progress value
            }
        });
        this.show(); // dismiss progress dialog
    }
}

You can optimize this code.

sundayokpokor
Offline
Joined: 2012-02-20
Points: 0

Thanks mixaz, let me follow your approach, i feel it will solve the problem, i will get back to you soon.