views:

317

answers:

6

Hi all,

I am developing an app. (like google talk) which at phone boot-up starts a background service which is continuously running. This service interacts with UI (means any request to server is first sent from UI to service & from service to server) & any response is sent to UI through service.

What i know to start background service at boot up is "Create an alternate entry point and use that to start the background service. "

right click the project properties then go to Application tab, then check "Auto run on startup" / "System Module"

is it right?

In Android u can achieve this Service using system-defined Service class. How to achieve this in Blackberry 4.5? I want to do it (UI & Service) in one project.

Any solution?

+3  A: 

You only need an alternate entry point if you want the program to behave in both the service mode, starting at boot and running in the background; and in application mode, having an icon in the home screen that the user can click to begin interacting with your software. In that case you need to have an entry point that tells the program "you are starting automatically at boot up", and one that tells the program "you are starting in response to user interaction".

There are other ways to handle this. If your application makes itself available to the user through ApplicationMenus, then you make the one and only entry point "Auto Run" and "System Module" so that it starts on boot, registers the menus and does not display an icon.

You can also use one entry point set to "Auto Run" but not a system module so the icon is displayed and detect the start on boot case using the ApplicationManager.inStartup() method.

The method you describe does work well for the type of application you are developing. It simplifies the initialization by allowing you to specify different arguments to the program in each entry point.

Richard
Correct, and I want to add that in simple background-running application you extend the Application class instead of UIApplication.
Max Gontar
A: 

Thanks for the reply.

I got a link for

"How To - Setup an alternate entry point for my application"

is it the right solution for starting Service?

I want the app. like email app. which will notify u when an incoming mail comes (like even though ur main application is minimized then also ur service is running in background which will continuously check for any incoming mail & will notify the main UI application through any app icon change)

So for this is there any class like Service class which will start at boot-up or "Setup an alternate entry point for my main UI application" is the only solution for this?

Shreyas
A: 

A background service is started at boot-up. But how to achieve the interaction between Service & UI (means any request to server is first sent from UI to service & from service to server) & any response is sent to UI through service.

How to achieve this communication between Service & UI ?

Shreyas
Max Gontar
A: 

Thanks for the reply..

I read this GlobalEveltListener & tried for handling the communication between the 2 apps (Service app. & UI app.) by starting the Service at auto-startup.

I m using the "Persistent Store" & accessing it in both the apps. But the Persistent Store name should be unique otherwise it gives "Linker error: Cannot start the Service app. as Persistent Store is multiply defined." But I have to access the Persistent Store the both the apps to make some database calls.

So now i m trying for handling the Service by putting both apps in one project. So that the Persistent Store will be unique.

How to achieve this communication between Service & UI in one project?

Shreyas
A: 

Please see the answer I have given earlier to a different question here. This essentially is an IPC mechanism between two running processes.

Kiran Kuppa
I m doing with RuntimeStore. Till now I m able to get objects in UI which are created in service. But its not switching from Service to UI?
Shreyas
A: 

Now I m able to show UI.

What I m doing is... after starting the service at start-up, I initialise the SocketConnection & put it in RuntimeStore.

When I click on any any button say Login from UI, it requests to server over the SocketConnection which I gets from RuntimeStore. Then I reads the response with the same SocketConnection from RuntimeStore & shows a dialog after successfully reading.

But I want like.. any request from UI first goes to service which will request it to server & any response from server first goes to service & service will notify it to UI. (like UI <-> Service <-> Server)

& meanwhile in background the read thread which I started at start-up should continulousy read from server & notify to UI if anything comes.

But now I think everything is going from UI.. m i right?

So how to do this communication?

Shreyas