• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Newbie: End app after alert

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a small application to understand the J2ME WTK, and I'm having a problem with displaying an Alert and then ending the app gracefully after it is found the screen is too small to run the app. For now, I have the following code:

The problem is trying to exit the app after the Alert box is displayed. If I don't issue notifyDestroyed() after the Alert box, the device shows a blank screen (i.e., no menu for the app to run again). If I insert the notifyDestroyed() after the Alert box, the error message is displayed for a split second, and the user is returned to the device menu.
Does anyone know how to get this to work properly?
Thanks!
 
author
Posts: 1436
6
Python TypeScript Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the best UI design is to put a "quit now" button on the alert and ask the user to click it when they are ready. That allows the user to read the alert message at his own pace.
If you have to do automatic quitting, you can put the whole thing into a separate thread and have it sleep for a couple of seconds before calling notifydestropyed
 
Stephen Pride
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Michael. I thought about the separate thread way, but haven't implemented it yet. I was trying to see if there was a "less coding" way of doing it, but perhaps not. Its funny, but with all the examples available on the net regarding J2ME, I haven't seen this particular scenario addressed exactly. Most of the apps I've seen address showing an Alert before continuing with the program vs. ending it. Thanks again.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're using MIDP 2.0, I think you should be able to call setCommandListener on the Alert, and then recognize its special Alert.DISMISS_COMMAND in your commandAction method and call notifyDestroyed there. I've not tried this though, and as it's rather obscure new MIDP 2.0 functionality you should be prepared for MIDP implementations to get it wrong. See the JavaDocs for class Alert for info on this approach.
With MIDP 1.0 you can't call setCommandListener on an Alert, so this solution doesn't work. I'd suggest using Michael's approach, or alternatively just ignore the Alert class and use a Form. If you want to get over-clever you could create a trivial subclass of Canvas with an empty paint() method and a showNotify() method that just calls the midlet's notifyDestroyed. Then display the alert using display.setCurrent(alert, new SneakyCanvas(this)), and when the alert leaves the screen your sneaky canvas will be shown, showNotify will be called, and it will call notifyDestroyed.
As I say, probably too clever for its own good - I might do this out of curiosity, but not in a production MIDlet .
 
Stephen Pride
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool! David, using your first approach works great. Here is what I did ...

Thanks again to both of you for the help!
[ October 31, 2003: Message edited by: Stephen Pride ]
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for moving up this question but it showed up as the only result on Google and David's second idea is so great, here is the code for that:Really great and conforms with MIDP 1.0.
[ July 07, 2004: Message edited by: Alexander Traud ]
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic