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
anildeveloper
Posts: 33
Registered: ‎07-16-2008
My Device: Not Specified
Accepted Solution

alternate entry point without restart

i have an application with two possible main objects:

 

  • UiApplication, for foreground process, we call it FG_UIApp
  • Application for background process on auto-run-startup, we call it BG_App


For debugging I want to kill the BG_App by sending it a GlobalEvent from FG_UIApp. Ok, this works perfect. Now the BG_App doesn't run. It only runs again, when I do a full reboot. But now I would like to be able to start the BG_App again without reboot. I thought of a way like this:

 

  1. user clicks the application 
  2. now checking, if BG_App is running, when it doesn't run, just start it
  3. for the user nothing happens, so he will again click the app
  4. now checking, if BG_App is running -> it runs, so now we can start FG_UIApp

For this I implemented the following code. Step 1 + 2 are working, but when I do step 3 the debugger tells me, that my application is already running. Is there any way to simulate the autorun-entry-point without rebooting?

 

 

public static void main(String[] args) { boolean startbackground = false; if ( args.length > 0 && args[0].equals("autostart")) startbackground = true; else { boolean runtimestorevalues_are_existing = false; // checking some values in the runtime-store, // which are set by BG_App

// if these values, don't exist, we start // the background-process if (!runtimestorevalues_are_existing) startbackground = true; } if (startbackground){ new BG_App().enterEventDispatcher(); } else { new FG_UiApp().enterEventDispatcher(); } }

 

 Regards, Anil

 

Please use plain text.
Administrator
MSohm
Posts: 14,554
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: alternate entry point without restart

Have a look at the link below.  You could get the ApplicationDescriptor for your alternate entry point and start it this way.

 

How To - Launch a third party application from another third party application
Article Number: DB-00455

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/How_To_...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
anildeveloper
Posts: 33
Registered: ‎07-16-2008
My Device: Not Specified

Re: alternate entry point without restart

Hello Mark!

 

it still does not work. lets call my application "foo". I tried many different combinations with invoking foo by an application-descriptor following your provided example. It seems, that the provided example works for 3rd-party-applications to invoke ANOTHER  3rd-party-application. But it seems not to work for foo to invoke foo. In every combination I tried, every time when foo invokes foo, the debugger says:

Starting foo Started foo(111) JVM: bklt @9922: timer JVM: bklt @9922: idle 3 JVM: bklt @9923: setTimer 19 Starting foo foo already running

 Anil

 

Please use plain text.
Administrator
MSohm
Posts: 14,554
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: alternate entry point without restart

The behaviour you are seeing is expected.  Alternate entry points do not equal 2 copies of an application running at the same time.  Alternate entry points allow an application to take different actions based on how it was started. 

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
anildeveloper
Posts: 33
Registered: ‎07-16-2008
My Device: Not Specified

Re: alternate entry point without restart

[ Edited ]

Hello Mark!

After playing with modifying ApplicationDescriptor it works. The solution is here:

 

 

 

/*
my cod-module is called foo
in my jde I have 2 projects
- foo (the gui-application, called with no arguments)
- fooautostart (the backgroundapp, called with the argument "autostart",
it is generally called, when the device is booting)
*/
public static void main(String[] args) {
if ( args.length > 0 && args[0].equals("autostart")){
new BG_App().enterEventDispatcher();
}
else {
RuntimeStore rts = RuntimeStore.getRuntimeStore();
boolean runtimestorevalues_are_existing = false;
/*
now checking some values in the runtime-store,

which are set by BG_App; if these values, don't exist,

we have to invoke the background app in simulating the

startup-entrypoint;
*/
if (!runtimestorevalues_are_existing){
try {
int modHandle = CodeModuleManager.getModuleHandle("foo");
ApplicationDescriptor[] apDes =
CodeModuleManager.getApplicationDescriptors(modHandle);
String[] args_for_descriptor = {"autostart"};
ApplicationDescriptor descriptor =
new ApplicationDescriptor (apDes[0], "fooautostart", args_for_descriptor);
ApplicationManager.getApplicationManager().runApplication(descriptor);

}
catch (Exception e){
System.out.println("background start exception ex: " +
e.toString() + ": " + e.getMessage();
}
}
new FG_UiApp().enterEventDispatcher();
}
}

Thanks and best Regards to Canada.

Anil


 

Message Edited by anildeveloper on 09-08-2008 10:35 AM
Please use plain text.