Blogs >> Education & Books >>
Push API, open your application on push
J2ME Push API :
It's a very powerful concept to receive some information asynchronously on particular port, instead of forcing the application to use synchronous polling techniques.
It is introduced on MIDP 2.0 (JSR 118).
How to invoke application:
Initially your application is on sleep mode. As soon as any push message comes to a particular port which is register for push messages, in place of moving into inbox, it invokes the application first.
It makes an alternate entry point for application to invoke it.
It does not make any change in application life cycle, but only creates an alternative way to start your application without invoking by user.
It's responsibility shared between AMS and MIDlet, which is split as :
1 : When MIDlet is on sleep : AMS monitors the push event continuously. When any push message hit the registered port, AMS invokes the appropriate MIDlet to handle it.
2 : When MIDlet is running : MIDlet directly handles the push event.
//This code execute when MIDlet activates by push
public void messageReceivedHandler (TextMessage receivedMessage) {
String senderAddress = receivedMessage.getAddress();
String receivedMessageBody = "No msg received as yet";
//Receives the text message from sms
receivedMessageBody = receivedMessage.getPayloadText();
System.out.println("Received Message = "+receivedMessageBody);
}
/**
* Notification that a message arrived.
* @param conn the connection with messages available
*/
public void notifyIncomingMessage(MessageConnection conn) {
if ((thread == null) || (conn == smsconn)) {
done = false;
thread = new Thread(this);
thread.start();
System.out.println("Notify Incoming Message received..");
}
else
System.out.println("Incoming Msg, but thread is alive");
}
|