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 8797229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:48:37+00:00 2026-06-13T23:48:37+00:00

i have JS which return the value function sendDisplay() { var dis = alert(reader.dom.find(‘controls_contents_container’).style.display);

  • 0

i have JS which return the value

function sendDisplay()
{
 var dis = alert(reader.dom.find('controls_contents_container').style.display);
 return dis;
}

in android i try to set the return value so i can make a if else statement in android

public class MainActivity extends DroidGap {

   @Override
    public void onCreate(Bundle savedInstanceState) {
        CookieManager.setAcceptFileSchemeCookies(true);
        super.onCreate(savedInstanceState);
        super.setIntegerProperty("splashscreen", R.drawable.cover);
        super.loadUrl("file:///android_asset/www/index.html",1500);   

    }


    @Override
    public void onBackPressed() {
        super.loadUrl("javascript:alert(sendDisplay())"); 


    }


}

when i alert in loadUrl method, its show value from JS. but i dont know how to set that value to android variable.

TQ

  • 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-06-13T23:48:39+00:00Added an answer on June 13, 2026 at 11:48 pm

    Take a look at Google’s guide section on Binding Javascript Code to Android Code. I’ll also post a short summary here:

    You’ll first need to set up a Java class:

    public class JavaScriptInterface {
        Context mContext;
    
        /** Instantiate the interface and set the context */
        JavaScriptInterface(Context c) {
            mContext = c;
        }
    
        /** Show a toast from the web page */
        public void showToast(String toast) {
            Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
        }
    }
    

    Then, you’ll need to add an instance of that class to your WebView as a javascript interface:

    WebView webView = (WebView) findViewById(R.id.webview);
    webView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
    

    Finally, you can call it using “Android.showToast(whatever)” from javascript, or you can call that javascript from your Java code:

    loadUrl("javascript:Android.showToast(whatever)");
    

    Which is a little redundant in the case of showing a Toast message. But hopefully you get the idea.

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

Sidebar

Related Questions

I have a controller function which return a response with a value, and I
I have one function which return value in this format: li#2.ui-widget-content li#6.ui-widget-content li#12.ui-widget-content li#1.ui-widget-content
I have a function which attempts to capture a return value from a calling
I have the following code , which gets a return value from a function
I have a function which checks the passed value and returns false or true,
Can I´m asking for advice. I have function which should return javascript object function
I have a Web Service with one WebMethod for which return value is boolean.
I have very basic question regarding return value of a function, and checking the
I am currently using nodejs and I have a function which return a body
I have a function which replace character. public static string Replace(string value) { value

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.