Motorola C450, C550, C370 technical manual Using startApp

Page 28

common error is to implement startApp( ) to execute instructions that are only intended to be executed once during MIDlet execution. The correct implementation is to include in startApp( ) those instructions which can and should be executed each time the MIDlet changes from the Paused state to the Active state. The same logic should be applied to pauseApp( ).

The code sample below shows implementation of using startApp( ). startApp( ) performs operations for the initial launch of the MIDlet as well as any operations that need to take place each time the MIDlet changes state from Paused to Active. Booleans are used to determine whether the MIDlet has started and whether it’s in the Active state. These Booleans can also be used by other MIDlet threads to determine state.

Using startApp()

package midp.demo;

import javax.microedition.midlet.MIDlet;

public class Demo extends MIDlet {

//The MIDlet has been started already private boolean isStarted = false;

//The MIDlet is in active state

public

boolean isActive = false;

// (in

most cases these booleans are used by other threads)

protected void destroyApp(boolean unconditional){ isActive = false;

}

protected void pauseApp(){ isActive = false;

}

protected void startApp(){ isActive = true; if (!isStarted){

//...Use getDisplay(), setCurrent(),

//and other initial actions isStarted = true;

}

}

The MIDP specification of javax.microedition.midlet allows for some latitude in the implementation, therefore, it cannot be assumed that all MIDlets are perfectly compatible with all devices. Some MIDlets may execute flawlessly on desktop simulators such as Sun’s Wireless Toolkit and contain a gain/loose focus mechanism such that the MIDlet transitions between the Paused and Active states and startApp() and pauseApp() are called.

Image 28
Contents Technical Manual Table of Contents Lcdui JAD Attributes Introduction PurposeAudience DisclaimerReferences Revision History Definitions, Abbreviations, AcronymsDate Name Reason Acronym DescriptionDocument Overview Introduction J2ME Introduction Java 2 Platform, Micro Edition J2MEMotorola J2ME Platform Resources AvailableDescription Display NetworkingFile & RMS Java VMGuide to Development in J2ME Developing and Packaging J2ME ApplicationsIntroduction to Development Page Installation OTA ProcedureDownloading Applications Program and Data space notes Starting Applications Java Application Installer/De-Installer JaidExiting Applications Launching Web Session for Http Download Error ChecksDownloading MIDlets XML Screen Renderings BombMan is back, now on your Taichi series of handsets Taichi handset New Games Application Management MIDlet LifecycleMIDlet Suite Installation MIDlet Suite De-installation MIDlet Suite Updating DestroyAppMethod Caller PurposeStartApp or the pauseApp Using startApp Java System MIDlet Control of MIDlet State TransitionsPage Network API Network ConnectionsClass Descriptions IOException when it detects a time-out condition URL FormatUDP Sockets TCP SocketsImplementation Notes Network API Lcdui DescriptionLcdui Functional Description Gaming API and SoundClass Hierarchy Using BackgroundMusic BackgroundMusic ClassBackgroundMusic Methods Gaming API containing a sound APIGameScreen Class GameScreen FieldsGameScreen Methods Public int getKeyStatesInformation, disabling key events can improve performance Using GameScreen GameScreenImageUtil Fields ImageUtil ClassImageUtil Methods Using ImageUtil RgbDataPalleteImage Constructor PalleteImage ClassPalleteImage Methods Using PalleteImage Public void setTransparentIndexint index throwsUsing Static and Animated Tiles PlayField ClassDefining View Windows Using SpritesPlayField Constructor 2N+1 2N + PlayField Methods Public void addSpriteSprite s throwsPage Public boolean collidesWithAnyTileSprite s throws Using PlayField PlayFieldUsing SoundEffect SoundEffect ClassSprite Class SoundEffect MethodsSprite Drawing Animation FramesSprite Constructor Sprite Methods Page Public final void drawGraphics g throws FileFormatNotSupportedException Using SpriteSprites Java Gaming Sound API Max Midi Extension SupportFileFormatNotSupportedException Constructors Java Gaming Sound APIVibe and Backlight Vibe and Backlight APIOverview Creating a MessageSending a Message PermissionsJAD Attributes JAD AttributesMandatory attributes for manifest files MIDlet-Name Record Management System Class DescriptionCode Examples RecordStoreTips CaveatsPhonebook Access Phonebook Access APIPhonebook Access API Permissions Sample of code to create object of PhoneBookRecord classSimmemory Sample of code for calling of ‘getMaxEmailLength ’ method Sample of code for calling of ‘isPrimaryint speedNo’ method Sample of code for calling of ‘getNumberCategories’ method Sample of code for calling of ‘setCategoryView’ method Sample of code for calling of ‘getUsedRecords’ method Int index = ReceivedRecord.getRecord1 ITAP Intelligent Keypad Text Entry APIAppendix a Key Mapping Key Mapping for the C370, C450, and C550Center Select END Appendix B Memory Management Calculation Available MemoryOnline FAQ Appendix CAppendix D Spec Sheets C370, C450, and C550 Spec SheetsDocumentation Motorola Developer Information ToolsReferences Purchase Motorola Developer Information Tools Motorola, Inc
Related manuals
Manual 110 pages 1.04 Kb