Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6342373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:13:44+00:00 2026-05-24T20:13:44+00:00

I am working on a project on embedding web app on android, following the

  • 0

I am working on a project on embedding web app on android, following the WebView demo, however I need to call on a gwt function when the javascript function ‘wave’ is called back by the android app:

<html>
    <script language="javascript">
        /* This function is invoked by the activity */
        function wave(s) {
               // call a gwt function and
               // pass 's' to the gwt function
        }
    </script>
    <body>
        <!-- Calls into the javascript interface for the activity -->
        <a onClick="window.demo.clickOnAndroid()"><div style="width:80px;
            ...
        </div></a>
    </body>
</html>

Any ideas on how to achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:13:48+00:00Added an answer on May 24, 2026 at 8:13 pm

    You will need to export any method you want to call from javascript into javascript global scope. What this means is that you cannot call an arbitrary java method from hand-written javascript. You must plan ahead and expose the necessary methods in javascript scope.

    The process is pretty simple:

    1. Write a JSNI method that creates a function in $wnd scope.
    2. From the body of this function call the java method using the JSNI JavaScript to java syntax.
    3. Call the method declared in step #1 during application startup (for example, from your entry-point onmoduleload)
    4. Call the function created in $wnd scope from your javascript. Make sure you do this after your gwt module is loaded and entry-point have been run.

    An example from GWT JSNI documentation with additional comments:

    package mypackage;
    
    public MyUtilityClass
    {
        //Method to be called from javascript, could be in any other class too
        public static int computeLoanInterest(int amt, float interestRate,
                                              int term) { ... }
        //This method should be called during application startup
        public static native void exportStaticMethod() /*-{
           //the function named here will become available in javascript scope
           $wnd.computeLoanInterest =
              $entry(@mypackage.MyUtilityClass::computeLoanInterest(IFI));
        }-*/;
    }
    

    EDIT:

    Passing parameters to Java method:

    When you call Java method that takes parameters, from javascript, you need to use a specific syntax:

    [instance-expr.]@class-name::method-name(param-signature)(arguments)
    

    For example, calling a static method that takes a String parameter will look like this:

    @com.google.gwt.examples.JSNIExample::staticFoo(Ljava/lang/String;)(s);
    

    Note that as we are calling a static method, ‘instance-expr.’ is omitted. The rest of the code is fully qualified class name followed by :: and method name. The Ljava/lang/String; after method name, specifies that we need to call the method that takes a String object as parameter. Finally s is the actual value for that parameter.

    Remember that param-signature, Ljava/lang/String; in our case, in the syntax uses JNI type signature specs, and is required by GWT compiler to select the correct method even if there are multiple overloaded methods with the same name. A param-signature is required even if the method is not overloaded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working a project where I need to generate a series of classes
I only added to an existing fully working project, the file com/android/vending/billing/IMarketBillingService.aidl (I didn't
When working with Project Euler problems I often need large (> 10**7) bit array's.
While working a project tonight, I ended up using one .js resource file for
I working on project and have problem with threading and update of UI. I
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I am working a project that does not have a trunk / branches /
I am working on project in Linux which involves 1) Static Lib in C++
I'm working on project that lets users choose some scientific authors and columnists and
I am working a project with many NUnit tests, that were already written long

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.