Oke I'm gonna try to post as much of the source as I can, because the project that I'm building may not be exposed 
But Oke here we go!
First a short explanation.
There are 4 classes involved!
- The Connection Class, this is a class that runs as a Thread and can send information to a server by calling connection.send(String data);
-The waitCanvas, is a Canvas that paints an image depending on a state (if state == 1 it paints the first image, if state == 2 it paints the second image, so on and so on). It has a engine to change the state.
-The waitEngine, is a Thread that changes the state of the WaitCanvas on a given interval
-The Mainclass, this is the class that is started and creates the other classes. When a user interacts with the UI and information has to be send.
First the Mainclass will display the waitCanvas and next the Main class will create a String of data and calls connection.send(data); After the connection method has returned the response of the server and that response is processed the next Displayable will be showed.
NOWWWWW..... The source
Class ServerConnection
Code:
import javax.microedition.io.*;
import java.io.*;
import java.util.Vector;
public class ServerConnection extends Thread {
private HttpConnection connection = null;
private Connector connector;
private MainSystem system;
private final String serverURL;
public ServerConnection(MainSystem system, String serverURL) {
this.system = system;
this.serverURL = serverURL;
}
public synchronized String send(String data) {
try {
if(serverURL != null) {
connection = (HttpConnection) Connector.open(serverURL);
connection.setRequestMethod(HttpConnection.POST);
OutputStream output = connection.openOutputStream();
output.write(data.getBytes());
output.flush();
output.close();
InputStream input = connection.openInputStream();
int contentLength = (int)connection.getLength();
if(contentLength < 1) contentLength = 4096;
byte[] raw = new byte[contentLength];
int length = input.read(raw);
input.close();
connection.close();
input = null;
output = null;
connection = null;
System.gc();
String response = null;
response = new String(raw,0 , length);
}
} catch (Exception ex) { system.log("send error :"+ex+" -> "+data); ex.printStackTrace();}
return "";
}
public void destroy() {
connection = null;
connector = null;
system = null;
}
}
Class WaitCanvas
Code:
import javax.microedition.lcdui.*;
import java.io.IOException;
public class WaitCanvas extends Canvas{
private Display display;
private WaitEngine engine;
private Image virtualScreen;
private Graphics drawGraphics;
private int screenWidth = 0;
private int screenHeight = 0;
private int state = 0;
private int maxState = 4;
private final String headerText = "Busy";
private String message = "";
private MainSystem system;
private StyleSheet styleSheet;
// used for the animation
private Image[] ani;
private int aniIndex = 0;
public WaitCanvas(MainSystem system) {
this.system = system;
this.display = system.display;
// create the engine with a interval of 300 ms
engine = new WaitEngine(this,300);
screenWidth = getWidth();
screenHeight = getHeight();
virtualScreen = Image.createImage(screenWidth,screenHeight);
drawGraphics = virtualScreen.getGraphics();
ani = new Image[8];
for(int i = 0; i < 8; i++) {
try {
ani[i] = Util.createImage("/hourglass/"+(i+1)+".png");
} catch (IOException ex) { system.log("Hourglass ani problem("+(i+1)+"): "+ex.toString());}
}
// start the engine
engine.start();
}
public synchronized void setMessage(String message){
state = 0;
this.message = message;
repaint();
}
public void paint(Graphics g) {
drawGraphics.setColor(255,255,255);
drawGraphics.fillRect(0,0,screenWidth, screenHeight);
drawGraphics.drawImage(ani[aniIndex],Util.div(screenWidth,2)-Util.div(ani[aniIndex].getWidth(),2),Util.div(screenHeight,2)-Util.div(ani[aniIndex].getHeight(),2),0);
if(++aniIndex >= ani.length) aniIndex = 0;
int headerX = 5;
int headerY = 5;
int messageX = 5;
int messageY = screenHeight - fontMessage.getHeight() - 5;
drawGraphics.setColor(0,0,0);
drawGraphics.drawString(headerText, headerX, headerY, 0);
String points = "";
// HERE STATE IS USED TO DETERMINE HOW MANY POINTS AFTER BUSY THERE WILL BE.
for(int i = 0; i < state; i++) points += ".";
drawGraphics.drawString(points, headerX+fontHeader.stringWidth(headerText)+1, headerY, 0);
drawGraphics.setColor(0,0,0);
drawGraphics.drawString(message, messageX, messageY, 0);
g.drawImage(virtualScreen, 0, 0, 0);
}
public void showNotify() { repaint(); }
public synchronized void setState(int state) { this.state = state; }
public synchronized int getState() { return state; }
public synchronized int getMaxState() { return maxState; }
public void suspend() { engine.suspend(); }
public void resume() { engine.resume(); }
public void stop() { engine.stop(); }
public void destroy() {
engine.stop();
engine.destroy();
engine = null;
display = null;
virtualScreen = null;
drawGraphics = null;
system = null;
}
}
Class WaitEngine
Code:
public class WaitEngine extends Thread {
private WaitCanvas waitCanvas;
private int interval;
private boolean running = true;
private boolean suspending = false;
private Object o = new Object();
public WaitEngine(WaitCanvas waitCanvas, int interval) {
this.waitCanvas = waitCanvas;
this.interval = interval;
}
public void run() {
while (running) {
if (suspending) {
try {
synchronized (o) { o.wait(); }
} catch (InterruptedException ie) { }
} else {
try {
try { Thread.sleep(interval); } catch (InterruptedException ex) {}
// CHANGE THE STATE
int state = waitCanvas.getState()+1;
if(state >= waitCanvas.getMaxState()) waitCanvas.setState(0);
else waitCanvas.setState(state);
waitCanvas.repaint();
} catch(NullPointerException ex) {}
}
}
}
public void suspend() { suspending = true; }
public void resume() { suspending = false; synchronized (o) { o.notify(); }}
public void stop() { running = false; }
public void destroy() { o = null; waitCanvas = null; }
}
Class MainSystem
Code:
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
public class MainSystem extends MIDlet implements CommandListener {
protected static final int STATUS_OK = 0;
protected static final int STATUS_ERROR = 1;
protected static final int STATUS_UNKNOWN = 2;
private Displayable lastView = null;
private Displayable lastViewLog = null;
Display display;
private ServerConnection connection;
private SigninForm signinForm;
private WaitCanvas waitCanvas;
//command
private Command okCommand = new Command("Login", Command.SCREEN, 1);
public MainSystem() {
display = Display.getDisplay(this);
signinForm = new SigninForm();
signinForm.addCommand(okCommand);
signinForm.setCommandListener(this);
waitCanvas = new WaitCanvas(this);
waitCanvas.addCommand(cancelCommand);
waitCanvas.setCommandListener(this);
connection = new ServerConnection(this,"http://localhost:5555");
connection.start();
}
public void startApp() throws MIDletStateChangeException {
display.setCurrent(signinForm);
}
public void destroyApp(boolean unconditional) throws MIDletStateChangeException {
destroy();
}
private void startWaiting(String text) {
waitCanvas.setMessage(text);
display.setCurrent(waitCanvas);
}
public void commandAction(Command c, Displayable s) {
if(s == signinForm) {
if(c == okCommand) {
startWaiting("Signin in");
String username = signinForm.getUsername();
String password = signinForm.getPassword();
String response = connection.send("fake_data:username>password");
process(response);
display.setCurrent(signinForm);
}
}
}
public void process(String data) {
// do something with the data;
}
public void destroy() {}
}
So that's it! I must note that is not the actual code, but a rip off... but the essential things of my problem are all included!
In short my problem is that the WaitCanvas is not shown while sending en getting data... BUT if the Canvas before the WaitCanvas was a Canvas it will be shown! (Strange isn't it)
p.s. I had to exclude my JavaDOC due to a maxlength problem (10000 chars)