views:

72

answers:

2

I'm writing a J2ME application that periodically updates server. how do i implement the functionality using J2ME? how do i run application on phone at startup and how do i keep it running?. I am planning to deploy the application it on symbian platform

+1  A: 

There are several ways to achieve this. I think the best one is to use a separate thread to handle your server communication/updates:

public class UpdateRunner extends Thread {
    ...
    public UpdateRunner() {
        // create an open sockets here
    }

    public void run() {
        while(true) {
            try {
                // send your messages/updates to server
            catch(...) {
                // handle errors like disconnections
            }
        }
    }
}

You can also use a timer to run some code periodically:

private class ServerTask extends TimerTask {
    public void run() {
        // send message here 
    }
}

then use it:

Timer serverTimer = new Timer();
serverTimer .scheduleAtFixedRate(new ServerTask(), 0, 500);

About running it on startup I dont think its possible, because the JVM has some security issues on letting software use network at will.

eMgz
+1  A: 

The feature to autostart MIDlets is called Push Registry. It allows for various events to start the midlet, typically SMS or bluetooth. Sony Ericsson has a push registry variant that starts the midlet on device startup, this is supported on at least the latest of their Symbian based handsets. For Nokia devices I suggest searching Forum Nokia.

Ola