×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    16

    Message while waiting to fetch data

    Hi

    My app is accessing the web to populate a list and while I wait I have the message "Empty" appearing for the list on the phone. Once the data is fetched I have the list of items of the list.

    How do I do to have / add a message saying "Please wait..." or "Working..." instead of having "Empty" displayed or something showing the progress.

    This happens on the phone but not on the emulator.

    Thanks

    Chris

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Message while waiting to fetch data

    Hi Chris!!

    Easiest option is to shove an Alert on the screen...

    Code:
    private Display display;    // = Display.getDisplay(myMidlet);
    private Displayable currentScreen;
    Code:
    // remember this, because we need to put it back later
    currentScreen = display.getCurrent();
    // create an alert
    Alert alert = new Alert(null, "Working...", null, null);
    alert.setTimeout(Alert.FOREVER);
    // this will add some kind of "busy" animation to the alert
    alert.setIndicator(new Gauge(null, false, Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING));
    // alerts automatically have a "dismiss" command, unless we add one... so add blank one to make it disappear
    // (unless you have a genuine "dismiss"/"cancel" command to add)
    alert.addCommand(new Command("\u00a0", Command.ITEM, 0));
    // make sure there is no command action (unless you want to add one)
    alert.setCommandListener(new CommandListener() {
        public void commandAction(Command c, Displayable d) {
            // empty
        }
    });
    display.setCurrent(alert, currentScreen);
    When the download finishes, just set the previous screen back to current.

    Code:
    display.setCurrent(currentScreen);
    Graham.

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    16

    Re: Message while waiting to fetch data

    Hi Graham

    Thanks for the answer!

    Assume that I am in a screen A and I want to go to a screen B. Screen B will be the screen that fetches data.

    Where do I put the different pieces of code you wrote?

    I was thinking that I put the code1 and code2 in A. But then currentScreen does not seem to work.

    I added a listener and resource manager to check that the download finishes. But the app stays on the alert.

    Chris

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Message while waiting to fetch data

    OK, if you're doing this on a screen transition, you don't want to return back to the same screen.

    Forget the references to "currentScreen" in the code I gave above, since you don't want the current screen anyway. Just put the alert on the screen with:
    Code:
    display.setCurrent(alert);
    And, in your listener:
    Code:
    display.setCurrent(theNextScreen);
    The alert won't disappear until you call setCurrent() to replace it.

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    16

    Re: Message while waiting to fetch data

    Ok. Thanks.

    Could you explain how to use a listener to make a screen visible when the http request has been completed? (the data of the http request are used in the screen).

    package view;
    public interface LoadListener {
    public void loadComplete(Object msg);
    }

    public class ResourceManager implements Runnable {
    private LoadListener listener;
    private Object message;

    public void load(LoadListener l, Object o) {
    listener = l;
    message = o;
    new Thread(this).start();
    }

    public void run() {
    // http call
    // url = "http://...";
    //hc = (HttpConnection) Connector.open(url);
    // treatement
    if (listener != null) {
    listener.loadComplete(message);
    listener = null;
    message = null;
    }
    }
    }

    Where to put the display.setCurrent(theNextScreen)?

    I call
    ResourceManager rm = new ResourceManager();
    rm.load(this, "test");
    in the currentScreen just after displaying the alert.

    It does not seem ok. I do not see how the "wait" is done.

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Message while waiting to fetch data

    Put the setCurrent() call in the loadComplete() method.

Similar Threads

  1. Fetch data from server using exe.
    By priya_ps in forum Symbian Networking & Messaging (Closed)
    Replies: 7
    Last Post: 2012-06-12, 07:02
  2. Replies: 1
    Last Post: 2011-02-23, 10:58
  3. How to fetch the attached image from the MMS message through the PC?
    By butterkacee13 in forum PC Suite API and PC Connectivity SDK
    Replies: 3
    Last Post: 2009-10-30, 05:33
  4. MMS Message Fetch
    By irfan.khan in forum Symbian
    Replies: 1
    Last Post: 2006-03-21, 11:34
  5. message waiting indicator?
    By suncc in forum General Messaging
    Replies: 0
    Last Post: 2004-12-25, 12:02

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •