Topic
1 reply Latest Post - ‏2011-07-27T08:23:51Z by SystemAdmin
SystemAdmin
SystemAdmin
110 Posts
ACCEPTED ANSWER

Pinned topic phonegap alert not visible

‏2011-07-26T12:56:07Z |
Hello,

I am currently experimenting with the combination of Phonegap and Worklight for android.

I created the following js file in the common/js directory:



// APP INSTANCE var HelloWorklightApplication = 

null; 
// CLASS DECLARATION HelloWorklight = Class.create( 
{   
// CLASS CONSTRUCTOR initialize : function() 
{ 
// INITIALIZATION CODE GOES HERE 
} 
}); 
// APP INSTANCE CREATOR (CALLED FROM BODY ONLOAD) HelloWorklight.init = function() 
{   
// CREATE THE APP INSTANCE HelloWorklightApplication = 

new HelloWorklight(); navigator.notification.alert(
"I am a native alert",null); 
};


As you can see, I added the *'navigator.notification.alert' *function to the intialize function. Afterwards, I built the app on the worklight server and I executed it on an Android emulator. Unfortunately, there is no alert box visible in the emulator.

What am I doing wrong?

Cheers,
Jan
  • SystemAdmin
    SystemAdmin
    110 Posts
    ACCEPTED ANSWER

    Re: phonegap alert not visible

    ‏2011-07-27T08:23:51Z  in response to SystemAdmin
    Hello jmes,

    Your call to navigator.notification.alert is not executed at all, because when you do a Worklight build, the HelloWorklight.js from the common folder is concatenated with HelloWorklight.js from the android folder, overriding the HelloWorklight.init function. You can open the android project and look at assets/www/default folder, and see the resulting HelloWorld.js.

    To solve the problem, you should put your code inside the 'initialize' function, which is not overridden, but sub-classed (the code from common is called first, and then the code from android).

    Bonus tip: You can use the normal alert function, as it's mapped to navigator.notification.alert.