站内搜索: 请输入搜索关键词
当前页面: 图书首页 > Wireless Java Developing with J2ME, Second Edition

Requesting a Wakeup Call - Wireless Java Developing with J2ME, Second Edition

Previous Section Next Section

Requesting a Wakeup Call

MIDP 2.0 allows MIDlets to request to be launched at a later time, in essence requesting a wakeup call from the implementation. The method is defined in javax.microedition.io.PushRegistry, which is kind of a weird place for it. All of PushRegistry's other methods have to do with launching MIDlets in response to incoming network connections; the class is fully described in Chapter 9. The following method in PushRegistry requests that a named MIDlet be woken up at a specific time:

public static long registerAlarm(String midlet, long time)
    throws ClassNotFoundException, ConnectionNotFoundException

You need to supply the class name of a MIDlet in the MIDlet suite, and time specifies exactly when you want the MIDlet to be launched, in the standard form as the number of milliseconds since January 1, 1970. (Chapter 4 contains a discussion of MIDP's classes and methods pertaining to time.)

If you supply a class name that is not found in the current MIDlet suite, a ClassNotFoundException is thrown. If the implementation is unable to launch MIDlets at specified times, a ConnectionNotFoundException is thrown.

If the MIDlet for which you are requesting a timed launch was previously registered for timed launch, this method returns the previous wakeup time.


Previous Section Next Section