Java – Making a J2ME Midlet sleep without threads

javajava-memidletmidpscheduling

Quick question … Using J2ME (CLDC 1.1, MIDP-2.1) is it possible to sleep the Midlet for a period of time (not using threads)… For example:

public class myMidlet extends MIDlet{
    public void startApp() {
        /* Sleep for 10 seconds */

        /* The answer was: */
        try {
            Thread.sleep(time_ms);
        } catch (Exception e) {}
    }
...

I don't use Java all that much, and don't want to program threads just for a simple sleep.

Thanks in advance

Answer Summary

My lack of Java knowledge. Examples I saw using Thread.sleep() led me to believe it was only usable in a thread object spawned by the Midlet … not the midlet itself. I didn't want to have to spool off the midlet logic into a thread to sleep it … But now I know the midlet runs in the default thread 🙂 Going to find that Java book I never read because I didn't think I would use the language ever

Best Answer

I didn't understand whether you mean putting midlet in paused state or just stopping execution for specified time.

If it's the latter, actually I don't undesrtand, why you don't want to use Threads, this is no big deal. You just insert three following lines wherever you need:

try {
    Thread.sleep(10000);
} catch (Exception ex) {}

That's all, nothing too complicating.

Related Topic