Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
aleitzinger
Posts: 45
Registered: 06-05-2009

Re: Something so simple is so difficult - App that monitors inbox

[ Edited ]

Hi,

       Finally got this all working after stitching together about 4 knowledge base samples.

I'm going to say again that this is such a standard application pattern I can't believe that RIM does not have a sample.

 

This took a week to figure out how all the pieces fit together and get it working properly (ok, I might be slow 8 but still it's ridiculous).

 

1.    Start by creating a singleton app instance using resource store

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/832062/How_to_...

 

2.    Implement Alternate entry point 

How To - Setup an alternate entry point for my application (http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/796557/800738/800901/...)

 

3.    Implement safe initialization (on startup) on your singleton

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/832062/How_To_...

 

4.    Add Screens to the UI Application, add the app's data to the Singleton class and implement the persistance logic (if you need to

       save your data ) there.

 

So,   I created 4 classes

 

MyUIApplication - implements UIApplication

                            Contains the static Main() which checks for alternate entry mode and if so creates

                             the MySystemListener and starts

                             its method to initialize and then starts its enterEventDispatcher

                             If the app is launched by the user, display my apps main screen MyMainScreen

                             and enter it's EventDispatcher

                             Implements a RefreshUI() method which is called by the singleton MyApplication

                             whenever the backgroud listeners

                             update the application's data

MyApplication  -  (Singleton) which implements a GetSingleton() method. This class implements #2 above

                            This class implements folder and message listeners to monitor the inbox which

                             updates my app's MyMainScreen. 

                            The constructor adds itself as a folderlistener to the inbox

                            The folder listener handler checks if the message is multipart and requests

                            download of the rest of the message

                            attaching itself as the MessageListener handler for the changed() event.

                            This class contains all of the applications data which is accessed by it and the MyUIApplication

                            This class has a reference to the MyUIApplication that is set by MyUIApplication.Main()

                            whenever the user launches the

                            GUI for the application. MyUIApplication sets this reference property in the Main() function

                            and removes it when the user 

                            exits the GUI application. Note: Keep the app running with requestBackground(),

                            don't call the exit(0) API.

                            Whenever the application's data is changed by the folder and message listeners check

                            if the MYUIApplciation reference

                            is not null and if not null call a RefreshUI() method which allows the MYUIApplication 

                            to refresh the MyMainScreen.

MySystemListener - Implements #3

                            Note: I changed the sample class's constructor to a DoInitialize() method since

                            the MyUIApplication contains the static Main()

                            NOTE - #@#@ the sample is incomplete. The class must extend the "Application"

                           class, not just implement

                            SystemListener.

                            Note: There are a bunch of other methods in the SystemListener interface that

                           need to be implemented so stub them in.

                            API reference:  http://www.blackberry.com/developers/docs/4.1api/index.html

 MyMainScreen   extendsMainScreen

                            Displayed via the static main Main() 

                            Displays the application's data by accessing the MyApplication.GetSingleton().mydataobjects

Message Edited by aleitzinger on 08-07-2009 11:19 AM
Message Edited by aleitzinger on 08-07-2009 11:21 AM
Please use plain text.