Running JavaScript within a Service in Android -


i have business logic written in javascript, code shared other non-android apps.

what best way use functions in piece of javascript within service in android.

afaik, there 2 options?

  • v8 built standard webview , superfast, no apk bloat.
  • rhino, tricky going on android?

focusing on v8/webview, when attempt access webview, function, get;

all webview methods must called on ui thread. future versions of webview may not support use on other threads. 

the warning being noted, doesn't work now. when set webviewclient up, nothing after loading url.

my question in 3 parts;

1) has had success running javascript in webview without ui thread?

2) how results functions inside javascript, webview interface "addjavascriptinterface " support loading parameter , sending java?

3) if either of above impossible.. guess i'll go rhino, tips appreciated, i've seen few blogs complaining of issues regards getting going on android , wondering if there "go to" version android maintained somewhere.

couldn't find regards v8 deep down in service.

ended using rhino, word of warning following down footsteps, it's incredibly slow.

just grab jar official latest distribution of rhino https://developer.mozilla.org/en-us/docs/rhino/download_rhino?redirectlocale=en-us&redirectslug=rhinodownload

js.jar need in zip. js-14 bigger java 1.4 compatible version don't need.

integration snap chuck jar libs folder.

below me scraping webpage using javascript (turning data better formatted json). parse.js script made coming assets folder.

rhino doesn't come dom, , env.js crashes out stackoverflow errors. overall, i'd solution slow , not supported...

public static void sync(context context, ){     string url = base_url;      string html = utils.inputstreamtostring(utils.gethttpstream(url));      timelist.add(system.currenttimemillis());      if(html == null){         utils.logw("could not board list.");         return;     }      string parsingcode = null;     try {         parsingcode = utils.inputstreamtostring(context.getassets().open("parse.js"));     } catch (ioexception e) {         utils.logw("could not board parser js");         return;     }      // create execution environment.     org.mozilla.javascript.context cx = org.mozilla.javascript.context.enter();      // turn compilation off.     cx.setoptimizationlevel(-1);      try {         // initialize variable scope bindnings         // standard objects (object, function, etc.)         scriptable scope = cx.initstandardobjects();          scriptableobject.putproperty(                 scope, "html", org.mozilla.javascript.context.javatojs(html, scope));          //load function         cx.evaluatestring(scope, parsingcode,"parsefunction", 1 , null);          // evaluate script.         object result = cx.evaluatestring(scope, "myfunction()", "doit:", 1, null);          jsonarray jsonarray = new jsonarray(result.tostring()); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -