aspose file tools*
The moose likes Java Micro Edition and the fly likes Newbie: End app after alert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Newbie: End app after alert" Watch "Newbie: End app after alert" New topic
Author

Newbie: End app after alert

Stephen Pride
Ranch Hand

Joined: Sep 14, 2000
Posts: 121
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!


SCJP
Michael Yuan
author
Ranch Hand

Joined: Mar 07, 2002
Posts: 1427
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


Seam Framework: http://www.amazon.com/exec/obidos/ASIN/0137129394/mobileenterpr-20/
Ringful: http://www.ringful.com/
Stephen Pride
Ranch Hand

Joined: Sep 14, 2000
Posts: 121
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.
David Price
Ranch Hand

Joined: Jan 22, 2003
Posts: 93
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

Joined: Sep 14, 2000
Posts: 121
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 ]
Alexander Traud
Greenhorn

Joined: Jul 07, 2004
Posts: 16
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Newbie: End app after alert