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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Trusted Contributor
anta40
Posts: 220
Registered: ‎07-26-2010
My Carrier: Telkomsel

How to set to autostart & run in the background?

How to set the app to both autostart & run in the background?

The autostart part is already done, by checking the "Auto-run on startup" checkbox.

 

But what about the background part?

I put Application.getApplication().requestBackground(); in the app constructor, and that makes my app always run in the background, which is not I not intend to.

 

What I mean is: every time the BB turned on, the app will also automatically run in the background (fetching data periodically). And if the app icon is clicked, then it will be shown.

Please use plain text.
Developer
gmuhammad
Posts: 55
Registered: ‎07-30-2009

Re: How to set to autostart & run in the background?

You can use alternate entry point of main() method. From the argument you can decide whether to run in background at startup or show application in normal way.

 

----------------------------------------------------------
feel free to press the kudos button on the left side to thank the user that helped you.
please mark posts as solved if you found a solution

Please use plain text.
Trusted Contributor
anta40
Posts: 220
Registered: ‎07-26-2010
My Carrier: Telkomsel

Re: How to set to autostart & run in the background?

Hmm... what should I use as the argument?

Please use plain text.
Developer
sonicboomboy
Posts: 465
Registered: ‎03-04-2009
My Carrier: some

Re: How to set to autostart & run in the background?

Check out this for more info. Maybe you find it helpful

http://supportforums.blackberry.com/t5/Java-Development/Make-a-running-UI-application-go-to-the-back...

Got resolved! Press kudo icon!
Please use plain text.
Trusted Contributor
anta40
Posts: 220
Registered: ‎07-26-2010
My Carrier: Telkomsel

Re: How to set to autostart & run in the background?

How do I get the ID?

Should I assign it manually?

Please use plain text.
Developer
peter_strange
Posts: 17,959
Registered: ‎07-14-2008

Re: How to set to autostart & run in the background?

requestBackground(); is a one off statement, it does not mean your application will stay in the background.  So the combination you have in place should work.  Since you are starting the Application at start-up time and you want this to be displayed, you should be starting a UiApplication.  Since clicking on the icon will just cause the existing app to be moved to the foreground, you should make sure that there is a screen ready to display.  To make sure that the app is not closed, you should make sure that it always does requestBackground(), rather than System.exit(0).  But all thes is relatively straightforward.

 

There is no need to use an Alternate Entry to meet this requirement. 

Please use plain text.
Trusted Contributor
anta40
Posts: 220
Registered: ‎07-26-2010
My Carrier: Telkomsel

Re: How to set to autostart & run in the background?

RuntimeStore appReg = RuntimeStore.getRuntimeStore();
synchronized(appReg){
   if (appReg.get(ID) == null) {
       appReg.put(ID, new Application(...));
   }
   Application MyApp = (Application)appReg.waitFor(ID);
}

 

What to fill the blanks with?

Please use plain text.
Trusted Contributor
anta40
Posts: 220
Registered: ‎07-26-2010
My Carrier: Telkomsel

Re: How to set to autostart & run in the background?

[ Edited ]

Anyway, now this is what I have in the app constructor:

 

public static final long MY_APP_ID = 0xf512941762fdb1c2L;
RuntimeStore appReg = RuntimeStore.getRuntimeStore();
synchronized (appReg) {
if (appReg.get(MY_APP_ID) == null){
appReg.put(MY_APP_ID, new Application() {
});
}
Application myApp = (Application)appReg.waitFor(MY_APP_ID);
}
synchronized (appReg) {
if (appReg.get(MY_APP_ID) != null){
Application myApp = (Application) appReg.waitFor(MY_APP_ID);
myApp.requestForeground();
}
}
Application.getApplication().invokeLater(new Runnable() {
public void run() {
// run this task every 3 hours
// blah blah blah
}
}, 3600*1000*3, true);

 

 

When the app icon is clicked, it won't show up.

Hmm.... :smileyindifferent:

Please use plain text.