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
Posts: 78
Registered: ‎05-17-2012
My Device: 9900 - OS 7.0 Torch device
My Carrier: Reliance

Run in background has problem

Hi All,

 

I am throwing the app to run banckground. if again user launch the app by clicking icon available on homescreen. Do I need to write any code to make it to foreground ?. With my knowledge,  while running the app in background, eventhough the user tries to launch the app, it will not start from main(), i.e it checks whether app running in background or not rt?

 

But In my case, when I tried to launch app again  when app is already running in background, its freezing, nothing happens and blocking the device.

 

Can anyone gives explanation regarding this.  Looking forward for your good help here.

Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: Run in background has problem

There is something similar we have done in our project...

 

You can kill the first running application before launching a new one, or can request to bring the app into foreground.

 

In my project it was a requirement to kill the app if it is already running.

Trusted Contributor
Posts: 141
Registered: ‎02-15-2012
My Device: 9800
My Carrier: Airtel

Re: Run in background has problem

Are yoy runing any background thread or any background operation(like calling webservices)??

Developer
Posts: 78
Registered: ‎05-17-2012
My Device: 9900 - OS 7.0 Torch device
My Carrier: Reliance

Re: Run in background has problem

Hi All

 

I am not calling any webservice. Through my application somewhere in mid of app, I throught the app to run in background. Then it automatically come back to home screen of the device. Again if user tries to relaunch the app, Do we need to kill the app ? or It shall it take the response to make the background running to foreground. I tried with/without killing the app when relaunch, It does not give proper result.

 

I had doubt when device takes responsibility to relaunch the app without killing ? or we need manually the kill the app.

Can you guys explain please.

Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: Run in background has problem

Hi 

I had similar issues ..That I have done in my project is  check if the app is running kill it first parametrically and relaunch again.

 

http://supportforums.blackberry.com/t5/Java-Development/Programmatically-kill-an-application/m-p/421...

 

Cheers

Rabi

 

Developer
Posts: 78
Registered: ‎05-17-2012
My Device: 9900 - OS 7.0 Torch device
My Carrier: Reliance

Re: Run in background has problem

Hi

 

Thanks for your reply

 

Can you please have a look on below code which I have written in main() method

 

ApplicationManager appMgr = ApplicationManager.getApplicationManager();
        int moduleHandle = CodeModuleManager.getModuleHandle("AppName");
        ApplicationDescriptor[] appDes = CodeModuleManager.getApplicationDescriptors(moduleHandle);
        int processId = appMgr.getProcessId(appDes[0]);
        appMgr.postGlobalEvent(processId, 0x12345678, 0, 0,null,null);
        
        ZipLockAppMain btgApp = new ZipLockAppMain();
        btgApp.enterEventDispatcher();

 

for this class, I have implemented GlobalListenerClass, in eventOccurred method, i have written system.exit(0)

like below

 

public void eventOccurred(long arg0, int arg1, int arg2, Object arg3,
            Object arg4) {
        System.exit(0);
        
    }

 

 

does this work?

I will forward to your response here

Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: Run in background has problem

i cant say...u need to try and test in ur application.

 

The theory seems to be ok to me.

 

You can always bring back the running applciation to foreground if u figure out that it is running.

 

final RuntimeStore rst = RuntimeStore.getRuntimeStore();

final Application app = (Application) rst.get(Constants.GUID);
if (null != app) {
app.requestForeground();
} else {
rst.put(Constants.GUID, this);
}

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Run in background has problem

I don't think killing the application and restarting it is the best approach.

 

My advice to you is either override the activate method or define another entry point to your application.

 

While overriding the activate method is much simpler, defending additional entry point sounds more suitable at your case.

 

One entry point will be in charge of the auto start scenario and the second will be activate when clicking on the icon.

 

Search the forum (or Google) for entry points and you will get several good examples.

 

E. 

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Run in background has problem

Can I encourage people NOT to put their entire application in RuntimeStore.

 

This means that the Application is not actually removed when the Application is closed, which means things like Weak References used by Listeners to the Application, and any objects references from the Application  will be retained. 

 

I realize it can be a useful approach in some specific circumstances but in these circumstances you absolutely must make sure you remove it when your application really exits.

 

Also be aware that if you have an icon, and no alternate entry point, and the app is autostarted and in the background, then pressing the icon will NOT take you through main again.  It will just attempt to foreground the existing application. 

 

I've not looked hard at this, but I agree with maadani - my initial thought given the requirements would have involved using an alternate entry point.