Android Hybrid Applications Remote Debugging

When developing an hybrid application for the android platform we can debug our code in JavaScript using the Chrome DevTools. In order to assist my students I chose to create a short demo for using this remote debugging capability.

The application I wrote in Java includes a simple single activity. The following is the code of this activity.

package com.lifemichael.ourdebuggingdemo;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class MainActivity extends Activity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        WebView ob = new WebView(this);
        WebView.setWebContentsDebuggingEnabled(true);
        ob.getSettings().setJavaScriptEnabled(true);
        ob.loadUrl("file:///android_asset/demo.html");
        setContentView(ob);
    }
}

The HTML document the WebView object renders includes the following code.

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <form name="myform">
        <br/>num 1: <input type="text" name="num_a"/>
        <br/>num 2: <input type="text" name="num_b"/>
        <br/><input type="button" onclick="calc()" value="+"/>
        <br/>result: <input type="text" name="result"/>
    </form>
    <script>
        function calc()
        {
            var a = parseInt(document.myform.num_a.value,10);
            var b = parseInt(document.myform.num_b.value,10);
            var sum = a+b;
            document.myform.result.value = sum;
        }
    </script>
</body>
</html>

The following video clip overviews this code sample, shows its execution and the remote debugging for its code using Chrome DevTools.

Share:

The Visitor Design Pattern

The Visitor Design Pattern

The visitor design pattern allows us to add operations to objects that already exist without modifying their classes and without extending them.

What are Anti Patterns?

Anti Patterns

Unlike design patterns, anti patterns just seem to be a solution. However, they are not a solution and they cause additional costs.

Virtual Threads in Java Professional Seminar

Virtual Threads in Java

The use of virtual threads can assist us with improving the performance of our code. Learn how to use virtual threads effectively.

NoSQL Databases Courses, Seminars, Consulting, and Development

MongoDB Design Patterns Meetup

The use of MongoDB involves with various cases in which we can overcome performance issues by implementing specific design patterns.

image of woman and database

Record Classes in Java

Learn how to define record classes in Java, and when to use record classes in your code. Stay up to date with the new Java features.

Accessibility | Career | Conferences | Design Patterns | JavaScript | Meetups | PHP | Podcasts | Python | Self Learning

Teaching Methodologies | Fullstack | C++ | C# | CSS | Node.js | Angular | Java | Go | Android | Kotlin | Swift | Academy

Front End Development | Scala | Architectures | Cloud | Big Data | Internet of Things | Kids Learn Programming

The Beauty of Code

Coding is Art! Developing Code That Works is Simple. Develop Code with Style is a Challenge!

Skip to content Update cookies preferences