×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    22

    isShown - not showing.

    Hi,
    I am having trouble with the setCurrent display.

    When the user selects a option from my menu, I want to display an alert (alertModeratorStatus - which has a gauge in it) showing that some work is done, and when the work is done, it must show the next screen with the populated data.

    However, the isShown always is false. I never see the alert. Why doesn't the alert gets displayed, timeout and then shows me the next screen? (listModeratorStatus). At the moment I only have a loop that never exists.

    Any help and ideas appreciated.



    case 5:
    // Insert pre-action code here
    getDisplay().setCurrent(get_alertModeratorStatus());
    while (!alertModeratorStatus.isShown()) {
    try {
    Thread.sleep(50);
    } catch (InterruptedException ex) {
    ex.printStackTrace();
    }
    }
    getDisplay().setCurrent(get_listModeratorStatus());
    //Insert post-action code here
    break;
    case 6:

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280

    Re: isShown - not showing.

    Quote Originally Posted by Peanuts1971
    Hi,
    However, the isShown always is false. I never see the alert. Why doesn't the alert gets displayed, timeout and then shows me the next screen?
    I assume the code you posted gets called from commandAction(). In that case you are blocking the main system thread, and it's that very thread that is in charge of updating the display.

    The thread is blocked until the new screen is displayed + the new screen cannot be displayed until the thread is unblocked = deadlock.

    You have to start a separate thread to do the work after calling setCurrent. In the end of your thread's run() method you can set the next displayable (get_listModeratorStatus()), and call any "post-action" code you need to call.

    shmoove

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    22

    Re: isShown - not showing.

    Hi Shmoove,
    Thanks for the quick reply.

    I must be missing something fundamental in my understanding of the main thread. And yes, it is within commandAction().

    Initially I had :

    case 5:
    // Insert pre-action code here
    getDisplay().setCurrent(get_alertModeratorStatus());
    getDisplay().setCurrent(get_listModeratorStatus());
    //Insert post-action code here
    break;
    case 6:

    However that did not work for me, since it never displayed the alert, only the list. Then I had the bright idea to put in the thread.sleep, to wait until the alert is shown, or as the saying goes, hell freeze over. Well, we know how that turned out.... no alert. I think I've read somewhere that the display sometimes have amnesia and don't show the displays...

    I read your advice, but are not 100% sure what you mean with "You have to start a separate thread to do the work after calling setCurrent" - what work are you refering to?

    Sorry for the stupids questions, I have still very green to MIDP / Java.

    PS: does it acually means that you can only have one setcurrent in one block? If I have
    getDisplay().setCurrent(A);
    getDisplay().setCurrent(B);
    getDisplay().setCurrent(C);
    getDisplay().setCurrent(D);
    it will only display the last one?

    Thanks.

  4. #4
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280

    Re: isShown - not showing.

    Using Threads in J2ME Applications
    Understanding MIDP System Threads
    Networking, User Experience, and Threads

    The first two links will explain the theory behind your problem.

    The third link has code you can use to solve your problem. The examples they use is for connecting to the network, but the same method can be used with any code that will take "long" (ie, more than a few milliseconds) to perform.

    shmoove

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    22

    Re: isShown - not showing.

    Thanks shmoove.
    I will try it and report back when done.

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    22

    Re: isShown - not showing.

    It worked! Thanks, now I see the alert.
    I keep checking a variable and when the variable is set to true (which means that I got all the data from the web server to build the list) I let the alert time run out. Very cool, it works, no problem.

    But (there is always a but with MIDP it seems), the list gets generated immediately and even tho it displays after the alert, it is empty, since at that time the data is not there yet. If I tell the list to loop and keep checking if the data is there before it builds, my UI freeze up again!

    I thought I will try adding yet one more thread, as per the alert example, but that gave some where behaviour, the alert still worked correctly, but the list did not show up anymore (not even empty) but rather the original menu where the user selected from!

    Sequence should be
    menu (where user selects to see the list)
    alert (telling the user the data is coming, hang ten)
    list (ok, heres the list!)

    but, as I said, the alert thread helped me out, no problem.
    adding another thread to do the same trick got me thrown back all the way to the menu again ??

    Any help appreciated.

    PS: it seems MIDP programming is all about thread handling, the "coding" is easy, I learned to do i = i +1 and y = "abc" 20 years ago, that never seems to change

    Thanks for all the help so far.

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    22

    Re: isShown - not showing.

    Thanks very much shmoove.
    I got it working now. Here is the code, for anyone who also got troubles with such a case.
    As mentioned before, I got around the alert by first setting it to continious, and then updating the timout to 3 seconds until the condition is met, then the timer just run out and I see the next screen... this was not a big problem, figured that one out myself, as I said before, biggest problem was the displays that were freezing.

    case 5:
    // Insert pre-action code here
    Thread t = new Thread() {
    public void run() {
    getDisplay().setCurrent(get_alertModeratorStatus());
    while (!disUserModeratorList) {
    alertModeratorStatus.setTimeout(3000);
    try {
    Thread.sleep(200);
    } catch (InterruptedException ex) {
    ex.printStackTrace();
    }
    }
    getDisplay().setCurrent(get_listModeratorStatus());
    }
    };
    t.start();
    //Insert post-action code here
    break;
    case 6:

Similar Threads

  1. problem showing image in WAP site
    By saikat_00 in forum Browsing and Mark-ups
    Replies: 5
    Last Post: 2006-12-21, 03:31
  2. showing and hiding sprites
    By desijatt in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2006-11-27, 18:43
  3. showing indicator
    By Devang Shah in forum Symbian
    Replies: 1
    Last Post: 2005-04-17, 15:57
  4. Series 60 emulator is not showing colours
    By carter_chen1997 in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2005-01-03, 10:39
  5. How to avoid showing the 'Select connection dialog'
    By chavasekhar in forum Symbian Networking & Messaging (Closed)
    Replies: 6
    Last Post: 2004-07-01, 10:40

Posting Permissions

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