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
Shwarup
Posts: 93
Registered: ‎08-18-2011
My Device: 9550
My Carrier: At&T
Accepted Solution

Alternate Entry Point for a Background application

Hi All,

 

I created alternate entry porint and displayed a launching Icon for my Background application.

 

and the application is launching using it.

 

The problem is :

               1. If I launch the application using this launching icon the value of "processID" shows "-1" even though the application is running.

                   int processId = ApplicationManager.getApplicationManager().getProcessId(appDescriptor);

                  

 

I used following Code Sample:

 

// MyApp.java

 

 

if

(args.length > 0 && args[0].equalsIgnoreCase("alt")) {

 

 

System.out.println(

"Launch app throw alternate entry point" );

// Here I am posting a global event to run MyApp.

 

}

else

{

MyApp app = MyApp();

 

if(!ApplicationManager.getApplicationManager().inStartup()){

app.invokeLater(

           new  Runnable(){

 

           public  void  run(){

                               startup();

                        }

              });

    }

 

    app.enterEventDispatcher();

 

}

 

 

Please help me if i miss any thing here.

 

Thanks

Shwarup Biswas

Thanks,

Shwarup Biswas
Please use plain text.
Developer
peter_strange
Posts: 19,598
Registered: ‎07-14-2008
My Device: Not Specified

Re: Alternate Entry Point for a Background application

There are a couple of ways I think this could go wrong. 

 

The most likely is the appDescriptor you use in here.

 int processId = ApplicationManager.getApplicationManager().getProcessId(appDescriptor);

How did you create this?

 

The other place is the location at which you issue this - has the application actually started? 

 

But one question, what are you trying to achieve? 

Please use plain text.
Developer
Shwarup
Posts: 93
Registered: ‎08-18-2011
My Device: 9550
My Carrier: At&T

Re: Alternate Entry Point for a Background application

Hi Peter,

 

Thanks for your quick reply.

 

I careated appDescriptor as bellow:

int processId = -1;

 

int handle = CodeModuleManager.getModuleHandle("MyApp");  // [MyApp is my background application it start on device start up. and I have created an alternative entry point for this application]

 

ApplicationDescriptor appDescriptor = CodeModuleManager.getApplicationDescriptors(handle)[0];

processId = ApplicationManager.getApplicationManager().getProcessId(appDescriptor);

 

and I wrote this code inside main method.

 

bellow in my main method:

 

public static void main(String[] args) {

if(args != null && args.length>0 && args[0].equalsIgnoreCase("alt")){

chekEnty=true;

}

else

{

chekEnty=false;

 }

int handle = CodeModuleManager.getModuleHandle("MyApp");

 ApplicationDescriptor appDescriptor = CodeModuleManager.getApplicationDescriptors(handle)[0];

Int processId = ApplicationManager.getApplicationManager().getProcessId(appDescriptor);

 if(processId  != -1 && chekEnty)

{

ApplicationManager.getApplicationManager().postGlobalEvent(APP_SERVICE_EVENT_GUID, 14, 0, APPLICATION_CLASS, newLong(APPLICATION_GUID));

 }

else

{

MyApp appObj= MyApp.getInstance();

if(!ApplicationManager.getApplicationManager().inStartup()){

 //Device is ready. Do the startup work as soon as it enters the event dispatcher.

appObj.invokeLater(newRunnable(){ 

publicvoidrun(){

startup();

}

});

}

 

// ["MyApp" is running now and In this place I checked again as before what is the process ID for "MyApp" but it show "-1". ]

 

}

 

//So My problem is when Third party application check either "MyApp" is already running or not  it found "PricessID" is "-1" so again "MyApp" get restarted.

 

// My requirement is that "MyApp" should not restart once it run in the background.

 

 

Thanks

Shwarup

 

Thanks,

Shwarup Biswas
Please use plain text.
Developer
maadani
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Alternate Entry Point for a Background application

Hi Shwarup,

 

Try replacing these lines:

int handle = CodeModuleManager.getModuleHandle("MyApp");

ApplicationDescriptor appDescriptor = CodeModuleManager.getApplicationDescriptors(handle)[0];

 

With this:

ApplicationDescriptor appDescriptor = ApplicationDescripto.currentApplicationDescriptor();

 

BTW, Is "MyApp" the name of your application or the module name of your application?

 

E.

Please use plain text.
Developer
peter_strange
Posts: 19,598
Registered: ‎07-14-2008
My Device: Not Specified

Re: Alternate Entry Point for a Background application

I agree with what has already been suggested. 

 

Also I do not see an enterEventDispatcher in your main routine,  It looks like it should be somewhere from your previous post, but I would be interested to know where.  And until that is run, you do not have a running application. 

Please use plain text.
Developer
Shwarup
Posts: 93
Registered: ‎08-18-2011
My Device: 9550
My Carrier: At&T

Re: Alternate Entry Point for a Background application

Hi Peter/Maadani,

 

Thank you for your reply.

 

>>I have “enterEventDispatcher” in my main routine.

>>You are right, I am getting process ID when I use

 

ApplicationDescriptor appDescriptor = ApplicationDescripto.currentApplicationDescriptor();

Instate of :

int handle = CodeModuleManager.getModuleHandle("MyApp");

ApplicationDescriptor appDescriptor = CodeModuleManager.getApplicationDescriptors(handle)[0];

 

But I need to check processID based on “RIM-COD-Module-Name: MyApp” because I will check this Module Name from third party application.

 

Please have a look at my .jad file, If I do any mistake in specifying Module Name:

 

RIM-COD-SHA1-4: bb 95 70 6e 5d 24 d7 12 50 50 23 5c 54 70 39 57 78 54 d1 91

RIM-COD-SHA1-3: 5d 91 b7 18 6b 10 cc c4 cc b0 57 c4 00 36 1f 82 c2 8c 3a e5

RIM-COD-URL-12: MyApp-12.cod

RIM-COD-SHA1-2: b4 3b 76 0a a1 b3 63 81 b6 62 81 29 2b f0 0c 02 3b ff dc e7

RIM-COD-URL-11: MyApp-11.cod

RIM-COD-SHA1-1: 44 4d 7c 4c c4 3b ec 1f b7 9d 51 d2 a4 03 59 68 30 2c 05 f2

RIM-COD-URL-10: MyApp-10.cod

RIM-MIDlet-Flags-2: 1

RIM-MIDlet-Flags-1: 2

MIDlet-Jar-Size: 1183750

MIDlet-Name: EMPSSO

MIDlet-Jar-URL: EMPSSO.jar

MicroEdition-Configuration: CLDC-1.1

MIDlet-Description: Gateway Service

RIM-COD-URL-9: MyApp-9.cod

RIM-COD-URL-8: MyApp-8.cod

RIM-COD-URL-7: MyApp-7.cod

RIM-COD-Module-Dependencies: net_rim_cldc,net_rim_os,net_rim_crypto_1,net_rim_bbapi_phone,net_rim_xml_org,net_rim_xml

RIM-COD-URL-6: MyApp-6.cod

RIM-COD-URL-5: MyApp-5.cod

RIM-COD-URL-4: MyApp-4.cod

RIM-COD-URL-3: MyApp-3.cod

RIM-COD-URL-2: MyApp-2.cod

RIM-COD-URL-1: MyApp-1.cod

RIM-COD-Size-9: 62164

RIM-COD-Size-8: 66964

RIM-COD-Size-7: 65344

RIM-COD-Size-6: 63364

RIM-COD-Size-5: 62292

RIM-COD-Size-4: 65596

RIM-COD-Size-3: 66444

RIM-COD-Module-Name: MyApp

RIM-COD-Size-2: 66220

RIM-COD-Size-1: 63532

RIM-COD-SHA1: 47 eb 65 30 b4 da ba 4e 47 fd 74 d5 07 18 04 6e c6 fe d2 83

RIM-COD-Size: 61136

MicroEdition-Profile: MIDP-2.0

RIM-COD-Size-12: 63160

RIM-COD-Size-11: 55308

RIM-COD-Size-10: 59856

MIDlet-Vendor:

MIDlet-2: MyApp, myAppIcon.png,alt

MIDlet-1: MyApp,,

RIM-COD-URL: MyApp.cod

RIM-COD-SHA1-12: d9 aa 83 e2 b4 4d cb 7a 3d b7 d8 f9 11 74 0f cc 2f fb 96 21

RIM-COD-SHA1-11: bb 33 bd dc b1 59 c3 ca dc 64 e9 e2 1a 9d 9c f3 c7 e5 6e 21

RIM-COD-SHA1-10: 8b 64 5e 82 a2 82 10 d4 15 a4 46 2f cc e0 ce 93 cd cc 93 c4

Manifest-Version: 1.0

MIDlet-Version: 1.0.0

RIM-COD-SHA1-9: db 4d 28 16 c0 19 7d b2 fa ab c8 63 70 9a 04 57 22 cf a9 18

RIM-COD-SHA1-8: 4a 02 b6 49 32 97 0b a3 11 63 ff eb 96 82 01 28 46 83 14 d6

RIM-COD-SHA1-7: 8e 9b 32 ee 69 1c 04 15 8f 4e 39 48 d8 e3 c1 d3 a4 74 82 11

RIM-COD-SHA1-6: 69 94 6b 80 41 31 08 80 bf 90 04 ea 0f b4 8b 00 b2 bd f0 a2

RIM-COD-Creation-Time: 1321977134

RIM-COD-SHA1-5: 30 5f 72 5f 71 a4 9e 4a 9f f5 70 1b a2 38 fd f2 ef 81 e0 8d

 

 

Thanks,

Shwarup Biswas
Please use plain text.
Developer
peter_strange
Posts: 19,598
Registered: ‎07-14-2008
My Device: Not Specified

Re: Alternate Entry Point for a Background application

Can you explain what you are trying to achieve again please?  I'm confused by these two statements:

 

"My requirement is that "MyApp" should not restart once it run in the background."

 

"But I need to check processID based on “RIM-COD-Module-Name: MyApp” because I will check this Module Name from third party application."

Please use plain text.
Developer
Shwarup
Posts: 93
Registered: ‎08-18-2011
My Device: 9550
My Carrier: At&T

Re: Alternate Entry Point for a Background application

Hi Peter,

The MyApp is a component of the Enterprise Mobility Platform. This application run in background. If a user want to access Wireless Enterprise Mobile Applications have to login using MyApp and once a user logged in can continue access n number of Wireless Enterprise Mobile Applications without login again.

Initially I don’t have any self launching Icon for this “MyApp”, It start on StartUp. If “MyApp” not start on startup, third party application launch it before communicate with it.

Now I need to have a self launching Icon too for this “MyApp” so I used alternate entry point to achieve it.

Now I can self launch “MyApp” using alternate entry point and I can login too. After login in “MyApp” I am launching another third party application and that third party application need to keep communication with “MyApp” for verifying current user while he access different enterprise application.

Third party application checks if “MyApp” is running before communication with “MyApp” as bellow:

int handle = CodeModuleManager.getModuleHandle("MyApp");

 

ApplicationDescriptor appDescriptor = CodeModuleManager.getApplicationDescriptors(handle)[0];

processId =  ApplicationManager.getApplicationManager().getProcessId(appDescriptor);

           

Now the problem is :

If I launch “MyApp” using self launching Icon (i.e. Alternate Entry Point”) the processId shows “-1” if I use above code to get the ProcessID.

But If I run “MyApp” from third party application as bellow:

int handle = CodeModuleManager.getModuleHandle("MyApp");

 

ApplicationDescriptor appDescriptor = CodeModuleManager.getApplicationDescriptors(handle)[0];

processId = ApplicationManager.getApplicationManager().runApplication(appDescriptor, false);

 

Then I get correct processId and it works fine.

 

looking forward to here from you.

 

Thanks

Shwarup

 

 

Thanks,

Shwarup Biswas
Please use plain text.
Developer
maadani
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Alternate Entry Point for a Background application

Hi Shwarup,

 

I'm also a bit confused.

 

On one hand, you say that your application "start on startup".

 

On the other hand, you say: "If "MyApp" not start on startup".

 

Unless you are compiling the same code twice, your application is either auto-start (start on start up) or not.

 

Assuming that you are not compiling twice and you did configured your application to auto-start, your application will run on start-up. AFAIK, in case there are problems that prevents the auto-run, they will also prevent the manual activation of the application.

 

If you wish to let the user/third party/your server/any other to change auto-start functionality, just keep a flag in your persistent storage that will let you know if the application should do some work. The application will remain alive in the background but will do nothing. This will enable third parties to communicate with your application even when it's suppose to be not active.

 

Let me know if it makes sense to you or if I'm completely wrong.

 

E.

Please use plain text.
Developer
peter_strange
Posts: 19,598
Registered: ‎07-14-2008
My Device: Not Specified

Re: Alternate Entry Point for a Background application

Yes I too am a little confused. 

 

But from I think I do understand, your plan to try to detect your application from other applications looks like the wrong approach.  There are at least two different ways that I would do something like this before I thought about trying to find some application using its process id. 

 

But before I suggest an alternative, let us make 100% sure we know what you are trying to do. 

 

You say this:

"If a user want to access Wireless Enterprise Mobile Applications have to login using MyApp"

Does this user log on using your app (in other words, the application will supply a userid and password, and your application will send this request off somewhere and come back with an 'approved' or not state.  Or does the application logon to your application and so the user has to supply credentials that are managed by your application, independently of anything else. 

 

Have you defined the 'API' between your application and the Wireless Enterprise Mobile Applications.  How do they pass data to your code and how do they get a response back?  How do you make these applications wait while the result is obtained?

 

You say

" I can self launch “MyApp”

Why would you do that?  What benefits are there to your invoking apps is this over them launching you? 

 

You say

"After login in “MyApp” I am launching another third party application and that third party application need to keep communication with “MyApp” for verifying current user while he access different enterprise application"

I can't see why this is different to what you have said previously.  If one third party app or 'MyApp' has signed in, then the same processing will apply. 

 

Now please do not get hung on on how you are doing this.  Ignore the App descriptor, I do not think you will end up using that mechanism to achieve what you want.  Please concentrate on the functionality you want, and let think about the technical approach to achieving it.

 

Jumping ahead a little, i can see how this might work.  You would have two different projects:

 

a) You would have a "shared" Library that provided a signon screen and an authentication backend.  This would remember if it had been authenticated, and if it had, subsequent requests for authentication could be immediately accepted without popping up the screen.  This Library would be invoked by the application programs (using some currently undefined means). 

 

b) Then you could have a very Simple application that only asked for an authentication.  It would use exactly the same approaches  as the other apps, so in fact can be used to 'test' this process and/or to signon before any of the real applications are run. 

 

Please use plain text.