Java Reference
In-Depth Information
mForm.addCommand(mSaveCommand);
mForm.setCommandListener(this);
}
public void startApp() {
Display.getDisplay(this).setCurrent(mForm);
}
public void pauseApp() {}
public void savePrefs() {
// Save the user name and password.
mPreferences.put(kUser, mUserField.getString());
mPreferences.put(kPassword, mPasswordField.getString());
mPreferences.save();
}
public void destroyApp(boolean flg) {
}
public void commandAction(Command c, Displayable s) {
if (c == mExitCommand) {
if (mPreferences == null) {
destroyApp(true);
notifyDestroyed();
}
else if ( !mPreferences.isSaving()) {
destroyApp(true);
notifyDestroyed();
}
}
else if (c == mSaveCommand)
savePrefs();
}
public void verifyFileConnectionSupport() throws IOException {
String version = "";
version = System.getProperty("microedition.io.file.FileConnection.version");
if (version != null) {
if (!version.equals("1.0"))
throw new IOException("Package is not version 1.0.");
}
else
throw new IOException("File connection optional package is not available.");
}
}
Note the use of the verifyFileConnectionSupport() method to assert the availability of the
optional package in the constructor. When the Exit command is selected, the MIDlet will
terminate only if the isSaving() method of the FileBasedPreferences instance returns false.
Otherwise, the background thread is still saving data to the persistent storage.
Search WWH ::




Custom Search