Design Tips

Team-Fly

This section contains some suggestions about creating networked MIDlets.

  • Use GET rather than POST. It's simpler, and you won't have to worry about fiddling around with the request headers.

  • Don't hard-code URLs. Put them in a MIDlet property in the application descriptor. This will make it possible to change the URL without recompiling your code.

  • Put network access in a separate thread. Network access always takes time; it shouldn't hold up the user interface. Furthermore, you must let your users know what's going on. Put up a "loading progress" type of message or some kind of indication that your application is trying to access a network resource.

  • Make sure you handle exceptions gracefully. Network connections on wireless devices are not tremendously reliable, so you should make sure you're prepared for the worst. Catch all your exceptions and do something reasonable.

  • Clean up after yourself. On a small device, resources are scarce, so be sure to close connections when you are done with them. try - finally blocks are especially useful for ensuring that unused streams and connections are closed.[1] The code in Jargoneer demonstrates this technique.

[1]You are probably familiar with the try - catch blocks that are used in Java for exception handling. The finally clause is not as well known, but it is very useful. Code in the finally block will be executed regardless of how control leaves the try block.


Team-Fly


Wireless Java. Developing with J2ME
ColdFusion MX Professional Projects
ISBN: 1590590775
EAN: 2147483647
Year: 2000
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net