Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Rebelllious
Posts: 46
Registered: ‎06-02-2013
My Device: 9780
My Carrier: MTS UKR
Accepted Solution

Need some explanation on alternate entry points

Hi everyone.

I'm rather new to BB development, as well as to development in general. Just trying to get how everything works, and sometimes unable to understand it.

I have an application already. For now it uses only one main screen, no matter from where it is run (either from application icon or from the systemwide menu item I added). What I need is to push different screens on different ways of running the app:

1. When the app is run from the icon in the home screen, I need to push the MainScreen, which is OK (at least it is done so for now and I know how it goes);

2. When the app is run from the menu item, I need it push a completely different screen, which is actually a popup screen (designed to popup over the application it is run from). I have already written the popup screen class, but don't really get how I should manage both screens in the MyApp class...

Any help will be appreciated.

Please use plain text.
Developer
simon_hain
Posts: 15,855
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Need some explanation on alternate entry points

this KB shows you how to use an alternate entry point:
http://supportforums.blackberry.com/t5/Java-Development/Set-up-an-alternate-entry-point-for-an-appli...

basically your main method is called with a different parameter, allowing you to react differently.

you have several options:
- keep the special UI in your menu item, no need to launch your app
- launch with an alternate entry point to display something else
- launch the app normally and send a global event to let it do something special
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
Rebelllious
Posts: 46
Registered: ‎06-02-2013
My Device: 9780
My Carrier: MTS UKR

Re: Need some explanation on alternate entry points

Thanks, simon_hain, I have already read this KB. But as I understand, that it is elaborated to start 2 threads - background and actual app thread. Yet, I need no background thread, at least for now. Am I misunderstanding the concept of the KB?

This is why I started this topic - I can't understand everything clearly enough...

Please use plain text.
Developer
simon_hain
Posts: 15,855
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Need some explanation on alternate entry points

what you do with the second entry point is up to you. a background thread is one option, but not the only one.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter_strange
Posts: 19,598
Registered: ‎07-14-2008
My Device: Not Specified

Re: Need some explanation on alternate entry points

This situation is a little complex, and you need to understand the concept of an Application Context, rather than an Alternate Entry.

 

Each application running on the BlackBerry has its own Application class.  A lot of things are 'local' to that Application class, for example, all the screens associated are accessible only to the Application that pushed them.  As a generic term, I use the term context - so each Application has its own context. 

 

Application context gets involved when you are talking about Alternate Entry.  An Application that is started using an Alternate Entry is different to the one started with the icon.  They can have different screens.  And the one started via the icon can not push screens onto the Application started at system start-up. 

 

However different Application context's can share code.  So, for example, the background Application that is started at device start-up can use the same code and push what look like identical screens, to the screens that the Application that is started by the icon can push.  This confuses a lot of people.  For example, people assume that any static variables will have only one occurrence - whereas in BlackBerry, they have one occurrence per Application context.  You do not share static variables between two Applications. 

 

Now ApplicationMenuItems bring a different issue to this.  You will notice that with these items you have two options.  Some require you to specify an ApplicationDescriptor, and some do not.  We will talk about the ones that do not first.  So these are the ones you add using this:

 public void addMenuItem(long id, ApplicationMenuItem item)

 

You should be aware that these actually run in the invoking Application's context.  You can add the Menu Item, and then the (usually background) Application that puts them in, can stop.  The MenuItems will remain and will be active.  They can push screens (or PopupScreens) from shared code, but are NOT in fact owned by the Application (in your case MyApp) that added them, the Popup screens belong to the Application the user is in when they pressed the menu item. 

 

So for example, if you have added the Menu item to the email application, the Popup screen will come from the Email application. 

 

It is generally considered good practice to process in your Application context.  Having a popup screen process in the email application is fine, but what it it fails?  Will this take the Email application down?  So you can swap from the original application's Application context to your own.  There are a number of ways of doing this, including global events. 

 

But getting to your case, you possibly don't have to.  You want the popup screen to appear over the top of that Application's screens, so you have to run this in that Application's context.  You do NOT need to have anything else running for this to work.  So your Alternate Entry just needs to start up, add these, and it can stop.  The Menu Items will still run and work.

 

OK, well that was discussing the entries that do NOT require an Application Descriptor.  The ones that do require this act differently. These are added using a call like the following:

public void addMenuItem(long id, ApplicationMenuItem item, ApplicationDescriptor application) 

I have actually never used one of these, so the following is just my understanding, never tested either.

 

In this case, the Application Descriptor will specify an Application context - it that Application context is not active, it will be started.  Then the processing will swap to that context and run the code.  So, if you had a popup screen in this case, then the screen would be seen in your Application, not the originating Application. 

 

I appreciate that this will actually has not answered all your questions (in fact has probably raised more questions), but I hope this should be a good start in your understanding of what is going on.  I suspect you will have problems in your popup screens when you try to communicate back to your real Application.  But hopefully this is enough to get you started doing that. 

Please use plain text.
Developer
Rebelllious
Posts: 46
Registered: ‎06-02-2013
My Device: 9780
My Carrier: MTS UKR

Re: Need some explanation on alternate entry points

Thanks to both of you, guys. Simon_hain just explained to me what I was confused about. And peter_strange did his best to tell me how the things look globally.

Well, let me get into more details. in my application I add the menu item systemwide using ApplicationMenuItemRepository. So, for now it is working fine and doesn't interfere with any application systemwide (and hope it is not going to). What I was interested in most of all is whether alternate entry points can include no background thread. I do have another questions after this, but will try to find solutions myself. The main question will be  "how to know my application is run from menu item, but not from the icon", but this is not the original one.

Thanks to you once again.

Please use plain text.
Developer
peter_strange
Posts: 19,598
Registered: ‎07-14-2008
My Device: Not Specified

Re: Need some explanation on alternate entry points

"how to know my application is run from menu item,"

 

The ApplicationDescriptor basically specifies your application and the start-up arguments.  So you can tell at start up time using the args on main().

Please use plain text.