Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
Calling javascript button function from webview

After creating a ‘register’ button in the webview, I want to navigate directly to a specific component when I click ‘func register’ in Kotlin.

Kotlin logic is structured like this.

// Android
inner class JavaScriptInterface
{
    @JavascriptInterface
    @SuppressWarnings("unused")
    fun register(data: String){
        navigate(
            ridday202208Ev.actionHaydxn2208EventToEventJoinForm()
        )
    }
}

This is javascript code.

 function register() {

  }

return (
 <button onClick={() => register()}></button>
)

When you click the register function in Javascript code, the webview recognizes the register function and wants to call navigate. I don't know how to deal with it.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want JS to be able to execute kotlin code, you need to call addJavascriptInterface(JavaScriptInterface(), "Native") That will create an object in JS called native with all the functions your annotated on that class. Calling one of them will call directly to Kotlin or Java. Remember that you'd call Native.register(), not just register() (the object name is the second parameter to the call above, change it to whatever you want).

Remember that any function you call like this can only take null, String, or Number (int, double, etc) as parameters. You can't pass objects. You can't pass arrays (you kind of can, but you need to pass a Java array, at which point its easier to write in Java). You can't pass functions. You can work around those limitations (except functions) by passing JSON strings and serializing/deserializing them as needed.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!