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
DFallak
Posts: 92
Registered: ‎06-02-2009
My Device: Rogers Curve 8900
My Carrier: Rogers
Accepted Solution

Multiple running instances of the same entry point

[ Edited ]

Anybody know whether this is possible?

 

1. Invoke my application more than one time using the same entry point. I would expect this would result in several threads running the same code in parallel.

 

2. I would like to be able to install my code module as usual, with a .jad file specifying one or several homescreen icons corresponding with one or several entry points. I would also like my application to be able to add homescreen icons that can invoke separate application instances using the same entry point.

 

 

Please use plain text.
Developer
ydaraishy
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: Multiple running instances of the same entry point

For 1: you don't need to spawn multiple processes in order to run multiple threads. A process can have multiple threads.

Please use plain text.
Developer
DFallak
Posts: 92
Registered: ‎06-02-2009
My Device: Rogers Curve 8900
My Carrier: Rogers

Re: Multiple running instances of the same entry point

My problem isn't that I don't know how to spawn threads, it's that I didn't know what the behaviour was when two icons are tied to the same entry point: would they end up running in two separate threads, or would they both be tied to the same thread?

 

After some investigation, the answer seems to be that they will both be tied to the same thread.

Please use plain text.
Developer
ydaraishy
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: Multiple running instances of the same entry point

I would imagine that they would be two separate processes, not threads. You can verify this by setting a variable to one value through one entry point, and not setting it through another entry point, and then checking the variable.

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

Re: Multiple running instances of the same entry point

Just thought I would share my understanding of how this all works.  It is probably wrong and I will look to someone to correct me, but it might shed some light on what you are trying to do here.

 

Every running process (a process is NOT a Thread, I'll come to Threads in a minute), has an ApplicationDescriptor.  The ApplicationDescriptor basically identifies an Application to start (i.e. an Application with a main()), and the parameters to pass to the main(). 

 

You can only have one of these running at one time.  So if you have started an Application with the String "test", then you can't start another instance of the Application with the same String.  But you could in theory start a another one with a different String.

 

And this is how Alternate Entry works, 

 

For the sake of this discussion, none of these Applications is auto-started.  Auto-start throws a curve ball that will just confuse at the moment.  Also all applications are UiApplications with Screens and are NOT System modules, they all have icons.  What I'm saying should make sense in these other circumstances, but reducing the options simplifies the explanation. 

 

So assume you have a normal UiApplication and have an Alternate Entry associated with it.  You associate a start-up String with the Alternate Entry that is different to the non Alternate Entry start-up.  On your Screen you will see the two icons.  Both icons go through main, push Screens, and 'enterEventDispatcher()'

 

When you click on the non Alternate Entry icon, the BlackBerry OS checks the running Applications and doesn't find one with the appropriate String, and so starts the Application, by going through main.  Then you task switch to another application using the Task Switch facility (without exiting the non Alternate Entry Application).  You return to the Home screen and click on your non Alternate Entry icon again.  This time the BlackBerry OS finds your Application running and just foregrounds it for you.

 

Now you click on the Alternate Entry icon - exactly the same thing happens.  But when you click it first, it does not find a matching Descriptor, even though there is a matching Application.  So it goes through main() again, this time with a different arg and the process will enterEventDispatcher(). 

 

Now we have two independent processes.  Each can have a set of (up to 16) Threads. 

 

OK, now to the questions:

 

"1. Invoke my application more than one time using the same entry point.."

Not sure what you mean by entry point.  There is only one entry point - it is main().  If the above has not explained whatever you wanted to know, then please ask another question.

 

"2. ... I would also like my application to be able to add homescreen icons"

I am not aware of a supported API for adding icons to the home Screen and associated a start up String to them.  So I think the answer to this question is no.

 

FInally...

 

There are likely to be lot more questions raised by this discussion.  For example,

"what if, instead of creating an application and  'enterEventDispatcher()', the main() processing just started a Thread.  Would clicking the icon actually start a new Thread given that one had already been started?"

If you have a question like that, can I suggest you try it and see.  And post your results here so we all know!

 

Hope this helps.

Please use plain text.
Developer
DFallak
Posts: 92
Registered: ‎06-02-2009
My Device: Rogers Curve 8900
My Carrier: Rogers

Re: Multiple running instances of the same entry point

[ Edited ]

 


peter_strange wrote:

...

"1. Invoke my application more than one time using the same entry point.."

Not sure what you mean by entry point.  There is only one entry point - it is main().  If the above has not explained whatever you wanted to know, then please ask another question.

"2. ... I would also like my application to be able to add homescreen icons"

I am not aware of a supported API for adding icons to the home Screen and associated a start up String to them.  So I think the answer to this question is no. 

...

Thanks for the help.

 

As for question 1, I was referring to alternate entry points as described in this  knowledge base article. My question should have been, would the separate icons call main() in separate processes?

 

After adding two icons in my JAD file and trying for myself, it looks like the two icons will end up activating the same process, not two separate processes.

 

As for question 2, this is what I'm starting to think as well...

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

Re: Multiple running instances of the same entry point

Re your question 1, in all my testing, where the alternate entry and the normal entry both create Applications (or UiApplications) and these enterEventDispatcher, these applications will be separate processes.

 

There are ways of using these alternate entries with a single Application instance, but that is beyond my capabilities of explaining in a single post!

 

You said: "it looks like the two icons will end up activating the same process, not two separate processes."  This is not my experience.  I would like to understand why you have reached this conclusion, and I would suggest that you be cautious about developing your application based on this premise.

Please use plain text.
Developer
DFallak
Posts: 92
Registered: ‎06-02-2009
My Device: Rogers Curve 8900
My Carrier: Rogers

Re: Multiple running instances of the same entry point

 


peter_strange wrote:
...

Now you click on the Alternate Entry icon - exactly the same thing happens.  But when you click it first, it does not find a matching Descriptor, even though there is a matching Application.  So it goes through main() again, this time with a different arg and the process will enterEventDispatcher(). 

 

Now we have two independent processes.

...



I tried adding a separate line in my JAD file that would create a new icon, like the following:

MIDlet-1: App,/icons/icon.png,
MIDlet-2: App,/icons/icon2.png,
RIM-MIDlet-Flags-1: 0
RIM-MIDlet-Flags-2: 0

 

I haven't tried with a different name yet. Maybe the different name makes the difference?

 

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

Re: Multiple running instances of the same entry point

So this is not an Alternate Entry.  What you are doing is providing a second icon that runs the same Application with the same ApplicationDescriptor (i.e. same startup args).  In this case, clicking the first icon and then the second icon, is exactly the same as clicking the first icon twice.  Hopefully what happens is clear from my explanation above.

 

Just for completeness, I'm providing a reference to the Alternate Entry KB article.

 

How To - Setup an alternate entry point for my application
Article Number: DB-00008
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800901/How_To_-_Setup...

Please use plain text.
Developer
DFallak
Posts: 92
Registered: ‎06-02-2009
My Device: Rogers Curve 8900
My Carrier: Rogers

Re: Multiple running instances of the same entry point

It seems to me like this knowledge base article is actually talking about activating the same process...

 

"Now, whenever the device is started, this main() method will be executed without any arguments, and the background thread will start. When the application icon is clicked from the main ribbon, the main() method will be executed with the argument specified in the above code sample ("gui") and the application can pop a screen to the foreground."

 

Separate threads are created, but not separate processes. I would be interested in seeing how one could actually start two different processes, with their own event dispatchers, using two different icons but only one code module.

 

If you were able to do this I'd be interested in figuring out how you did it!

Please use plain text.