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
neoknip
Posts: 38
Registered: ‎10-27-2010
My Device: Blackberry Torch 9800
Accepted Solution

How to avoid creating two instances of the application , when using alternate entry point?

Hi, I am having an application which starts up on auto run, for listening to the incoming SMS.

 

1) the main entry point of the application is , when the application icon is clicked.

2) The alternate entry point of the application is during auto startup of the device(autorun property is checked and system module property is also checked)

 

How to avoid creating two application instances. as the main function is called twice in this case.

 

3) In main function, during the autostartup entry .. i am creating the instance(app) to the application and invoking 'app.addSystemListener(this)' to add system listener to the application. next , i am invoking enterevendispatcher method, so as to start the sms listening thread when the PowerUp() function is invoked.

 

4) Question : When the application is entered through the icon, i need to show the main screen. But i shouldn't create a new instance for the application. How can i achieve this?

Please use plain text.
Developer
Hithredin
Posts: 404
Registered: ‎06-03-2010
My Device: Z10 Red

Re: How to avoid creating two instances of the application , when using alternate entry point?

[ Edited ]

Hi

 

When the application is launched from the icon, you should not call "enterEvenDispatcher" .

 

1) You have to check if the application is already launched, thanks to the result of ApplicationManager.getApplicationManager().getProcessId () ;

 

2) If it exists, just request foreground, else enter the EventDispatcher

 

 

If you need to push a screen to your application when you clic the icon, you may take profit of the Post Global Event to notify your application that it should push your mainScreen.

Please use plain text.
Developer
simon_hain
Posts: 16,134
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to avoid creating two instances of the application , when using alternate entry point?

you don't have to use your main application in the autostart entry point.

if you want to you can just remove the system module property and use only the autostart entry point, your app will be started in the background and, on click on the icon, get to the foreground.

 

Or you can just start an application in your autostart part, register it as a system listener and provide the events to your main app (if it is running) using global events (or process them in the background app).

----------------------------------------------------------
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
neoknip
Posts: 38
Registered: ‎10-27-2010
My Device: Blackberry Torch 9800

Re: How to avoid creating two instances of the application , when using alternate entry point?

Thanks Hithredin,

 

I tried ur logic. I used globalevent listener.

I used applicationmanager and application descriptor to find my process id. and i posted a global event. i was able to bring the app to the foreground and push my mainscreen.

 

But i am facing another issue.

When i close the app, i am overriding the onClose() method of my main screen as follows

public boolean onClose(){
            close();
            iUIApp.requestBackground();
            return true;
        }

The application is closed. 

 

so when i click the icon of the application next time, it is calling the main again. but this time applicationmanager.getvisibleapplications() couldn't find the application instance. so the system exits here.

 

To avoid this i tried removing the invoke of close() method in the onClose(). this time it is able to work properly, but i am finding the application in the ribbon(which is not desired).

Please use plain text.
Developer
neoknip
Posts: 38
Registered: ‎10-27-2010
My Device: Blackberry Torch 9800

Re: How to avoid creating two instances of the application , when using alternate entry point?

Thanks for the suggestion simon,

As per ur suggestion. U mean that I can have only one project and remove the alternate entry point?

 

It seems simple and clear. But i have one issue here. I dont want to show the application icon in the ribbon(when the BB button is long pressed). How can i achieve this?

 

 

Note : Even in my present logic i can still see the application icon in the ribbon. As per my current implementation,

I have the alternate entry point (autorun startup) as a system module.

I have the icons for the main entry (gui part which is not autostart).

 

How can i avoid the application icon in the ribbon?

Please use plain text.
Developer
simon_hain
Posts: 16,134
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to avoid creating two instances of the application , when using alternate entry point?

this won't be possible that way, the icon will be visible on the ribbon. I use this mechanism myself.

I use the other way on some projects as well.

----------------------------------------------------------
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
Hithredin
Posts: 404
Registered: ‎06-03-2010
My Device: Z10 Red

Re: How to avoid creating two instances of the application , when using alternate entry point?

Do you have to always keep  an instance running, (without ribbon of course) if you close your application?

 

If true, it may be possible to launch an instance of your app without ribbon in your onClose(); just before killing it.

Please use plain text.
Developer
neoknip
Posts: 38
Registered: ‎10-27-2010
My Device: Blackberry Torch 9800

Re: How to avoid creating two instances of the application , when using alternate entry point?

Hi Simon,

Thanks for the reply,

I understand that , its not possible to avoid the icon on the ribbon, without making it a system module. But if we make it as a system module, we cant get the icon on the application screen as well....

am i correct?

Please use plain text.
Developer
neoknip
Posts: 38
Registered: ‎10-27-2010
My Device: Blackberry Torch 9800

Re: How to avoid creating two instances of the application , when using alternate entry point?

Hi Hithredin,

I need to keep the application active all the time. So as to keep the SMS listener active.

Please use plain text.
Developer
Hithredin
Posts: 404
Registered: ‎06-03-2010
My Device: Z10 Red

Re: How to avoid creating two instances of the application , when using alternate entry point?

Have you tryed relaunching your app in  background mode before closing it?

 

Or what about creating two applications: one module and one graphics?

Please use plain text.