Skip to main content

If you want to move away from Windows try Linux this a good option for you

You can have a working Raspberry Pi 5 working including buying a mouse and keyboard get wireless and monitor for around £110 or if you want a bigger harddrive or SD card with 120gb, it goes up to the total cost of around £210. I have not used Windows in like 4 years I guess after Windows 10 and saw all it's issues stopped using it. I  have three or four Pis so far including pi 2 and 3 and 4 so far. Windows is probably harder to work than Linux for installing or making improvements. Whenever Windows did updates had to spend a few hours or longer changing or it get super slow again. https://www.theengineer.info/2025/01/introduction-to-being-anonymous-online.html Don't get put off by some Linux elitist people who see themselves as superior to all non Linux people or people use different ones such as Mint or Debian among others you could install. Rasbian is  a debrian system  Cases are good way to protect plus it allows you to keep them running better since move less than no ...

2015/04/05/Execute-JavaScript-in-Android-without-WebView/



April 16, 2022

The reasons I need do some Javascript code in Andriod based project was because of me running the background thread (in doinbackground part in an Asynctask), I want want to use Webview


Why not WebView


The first problem here is that Webview is heavy which then makes it run slow overall which is bigger problem when you are doing large kind of proejct and you need to add as well a lot of webview related setting which slows things done further when you want to do things like code snippet so my thoughts it’s not worth doing it because of these sort of problems overall.


Second main points I want to make which is UI related webview should be created in a UI thread which will then load Javascript code in the background of the thread then pass the results bac kto the UI it’s workable overall but it’s not safe in my thoughts.


If you can call methods on webview from any other thread than your app UI thread it can cause unexpected results. https://developer.android.com/guide/webapps/migrating#Threads


Last but not final Webview is fragmented after Android 4.4 or level 19 is using Webview based on Chromium style and even oo this is a good thing my mindset is 4.3 so a older version which could give you problems. You should try and code two versions of Webview in related code to just try and make it work. https://www.theengineer.info/2023/02/google-drive-programming-style-and.html


A lot of code should be re-wrote.

JavaScript  Brand computer graphic


Luckily, the good people in Mozilla make a project called Rhino. It is typically embedded into Java applications to provide scripting to end users.


How to use Rhino?


Rhino is a open source project, you can get the source code using this command:


git clone https://github.com/mozilla/rhino.git


Of course, you don’t have to get the source code. If you want to use it in your Android


project. Download Rhino first, unzip it, put the js.jar file under libs folder. It is very small, so you don’t need to worry your apk file will be ridiculously large because of this one external jar.


Here is some simple code to execute JavaScript code.


Object[] params = new Object[] { “javaScriptParam” };


// Every Rhino VM begins with the enter()


// This Context is not Android’s Context


Context rhino = Context.enter();


// Turn off optimization to make Rhino Android compatible


rhino.setOptimizationLevel(-1);


try {


Scriptable scope = rhino.initStandardObjects();


// Note the forth argument is 1, which means the JavaScript source has


// been compressed to only one line using something like YUI


rhino.evaluateString(scope, javaScriptCode, “JavaScript”, 1, null);


// Get the functionName defined in JavaScriptCode


Object obj = scope.get(functionNameInJavaScriptCode, scope);


if (obj instanceof Function) {


Function jsFunction = (Function) obj;


// Call the function with params


Object jsResult = jsFunction.call(rhino, scope, scope, params);


// Parse the jsResult object to a String


String result = Context.toString(jsResult);


}


} finally {


Context.exit();


}


As you can see, it is quite easy. You can dig up more in Rhino document.


Proguard & Obfuscation


You can set up Rhino’s proguard setting by adding this following line into your proguard-android.txt file.


-keep class org.mozilla.javascript.** { *; }


When you run the assembleRelease task, with minifyEnabled true of course, you still can see a lot of warning like these:


Warning: org.mozilla.javascript.tools.shell.JSConsole: can’t find referenced class javax.swing.JMenu


Warning: org.mozilla.javascript.tools.shell.JSConsole: can’t find referenced class javax.swing.JMenu


Warning: org.mozilla.javascript.tools.shell.JSConsole: can’t find referenced class javax.swing.JMenu


Warning: org.mozilla.javascript.tools.shell.JSConsole: can’t find referenced class javax.swing.ButtonGroup


Warning: org.mozilla.javascript.tools.shell.JSConsole: can’t find referenced class javax.swing.JScrollPane


Warning: org.mozilla.javascript.tools.shell.JSConsole: can’t find


referenced class java.awt.event.ActionEvent


Warning: org.mozilla.javascript.tools.shell.JSConsole: can’t find referenced class java.awt.event.ActionEvent


Warning: org.mozilla.javascript.tools.shell.JSConsole$1: can’t find referenced class javax.swing.filechooser.FileFilter


Warning: org.mozilla.javascript.tools.shell.JSConsole$2: can’t find referenced class java.awt.event.WindowAdapter


Warning: org.mozilla.javascript.tools.shell.JSConsole$2: can’t find referenced class java.awt.event.WindowEvent


Warning: org.mozilla.javascript.tools.shell.JSConsole$2: can’t find referenced class java.awt.event.WindowEvent


Warning: org.mozilla.javascript.xml.impl.xmlbeans.LogicalEquality: can’t find referenced class org.apache.xmlbeans.XmlCursor


Warning: org.mozilla.javascript.xml.impl.xmlbeans.LogicalEquality: can’t find referenced class org.apache.xmlbeans.XmlCursor


Warning: org.mozilla.javascript.xml.impl.xmlbeans.LogicalEquality: can’t find referenced class org.apache.xmlbeans.XmlCursor


Luckily, evan with these warnings, the app runs fine. You can ignore them(that’s what I do), or adding this line inot your proguard-android.txt file.


-dontwarn org.mozilla.javascript.**


Comments

Popular posts from this blog

SGIN Laptop 15.6" Display Laptop 12GB RAM 512GB SSD Storage(TF Card 512GB), Celeron, Full Size Keyboard, 2xUSB 3.0, Dual Band WiFi (Black) Brand: SGIN

 Key problems here The mouse can click itself without someone touching it can't be switched of meaning anything you trying to do you can't shut it off meaning you are screwed when the mouse stops working they offered me £50 discount if I received many instead of trying to trick me to give good review make a better product? IT scams at me low quality crap from China made using second hand parts or poorly designed a equipment it stopped working very quick after I  started it and also I noticed it Struble to install Windows new system on the computer to complete it crashed a few times here on the first day I Got it.  https://www.theengineer.info/2024/01/is-windows-11-as-bad-as-so-many-people.html Microphone does not work well and it can work or not work at random. Speaker is super quiet hard to hear anything using it and also  it at random makes a horrible loud sound even when you not doing anything major with the computer real big appointment here. Everything seem to o...

Is Windows 11 as bad as so many people claim?

 First thoughts It loads fast it has a much better display than Windows 10.  I was not a fan of Windows 10 it was overall very unattractive to see or work with overall and they tried so hard to like force the app ideas towards people which did not improve the user experience in anyway overall just make things get slow or not work well overall. Only thing I did not like the idea of being forced to make a email address or use run it seemed pretty overkill to me.  https://www.techradar.com/news/windows-11-home-and-pro The start up system is a bit slow here since so much updating has  get done in order for it to be ready to work. It would be good idea to not force people to start using Edge give other options such as Chrome or Brave or something else would be good idea since Edge is pretty slow running overall and not that good from a speed viewpoint Brave is my favorite browser at the moment for speed improvements and also because it protects your data better than Googl...

Amazon website thoughts

  Table of contents Introduction Pros Cons General thoughts about the website Final points The idea behind Amazon is to allow people to be able to buy and sell products easily where all the parts are done from you once you add your payment  account from the Bank it should workout problems normally Sometimes accounts are not able to work in it I found a few times that the website does normally load incredibly fast which is key area of importance in regards to having any website but mostly for e-commerce since speed increases sales a lot of time for why it would be a good idea to allow people to make the purchase fast without big delays which is often a problem when it comes to website building stuff like Wordpress often horrible for e-commerce even when you use Woocommerce through it all.  https://www.theengineer.info/2024/01/sgin-laptop-156-display-laptop-12gb-ram.html Pros Loads fast Easy to find things normally Easy to make a purchase normally Cons Make canceling produc...