Java Reference
In-Depth Information
class ID must be defined for each SNAP Mobile game; you can con-
figure it manually for the emulated environment in the Configuration
tab
Session smSession : a session to the SNAP Mobile server through
which all requests requiring login are sent and received.
In the startApp() method, we create a new instance of Console
and set it as the main display. We then make the JAD file parameters
available to the SNAP Mobile API using this call:
// Make the JAD file parameters accessible
Parameters.setInstance(new MIDletParameterAdapter(this));
This ensures the SNAP Mobile API can read important parameters
from the descriptor file such as SNAP-Mobile-URLs , which defines the
server to connect to (in this case, our local emulation environment).
After setting the display and required parameters, we are ready to log in
to the server. This is done by creating an instance of the SMClient class,
passing it an instance of a class implementing the SnapEventListener
interface. Most of the SNAP Mobile programming is event-driven: you
send a request using the Session object and receive an asynchronous
response in the form of a call to one of SnapEventListener 's methods.
In this example, we pass an instance of the SnapEventListener-
Adapter class.
Having created the SMClient instance, we log in to the server, by
calling:
smClient.loginSingleSignon(username, password, null, null, gameClassID,
null, 0, null, 0, false, null);
The main operation here is to pass the username, password and game
class ID to this method, so the server can validate our game and establish
a session with it. All the other parameters are given default values, as they
are not important to this example. For more details on their meaning,
please check the javadoc documentation in the docs folder of the SNAP
Mobile SDK installation.
Let us now see how to handle the events that are sent back to
the game in response to our requests. They are implemented in the
EventListener inner class. In the errorReceived() method we
can inform the user of an error condition and how to resolve it:
public void errorReceived(int code, boolean mustReturnToMainMenu) {
console.println("Error received with code" + code, Console.RED);
Search WWH ::




Custom Search