liori
liori

Reputation: 42277

Javascript app in Android

I am new to Android programming, and looking for some general knowledge. I am considering writing logic of my application in javascript so that the same code could be executed in a webapp and in a desktop application. Would it be possible to also have it working on Android? I know that:

Would it be possible to write a simple Java app that would embed an HTML widget with javascript code and provide some wrapper to access necessary API?

I am not looking for a fully portable thing--I intend to adapt UI to each environment manually. I just would like to have the internal logic common to all ports.

Upvotes: 9

Views: 24123

Answers (4)

jgleoj23
jgleoj23

Reputation: 262

Consider GWT, a Java to javaScript compiler. You can write your logic and a lot of other code in plain old Java(There are a few things(e.g. reflection) that you can't do like reflection but you wouldn't be able to do it in javaScipt either) Applications like Google inbox are using GWT to reuse a lot of their code in javaScript. They don't just reuse logic either. You can reuse dependency injection, your architecture, AJAX calls and more. Also, GWT is faster than javaScript in both the browser and the JVM. The biggest problem you might have with GWT is that it's more complicated javaScript. Regular Java is already more complicated. Making it work on both the JVM and browser can only make things more complicated. Also, GWT was designed from the ground up for extremely complciated web apps.

Upvotes: 0

PhoneGap allows you to write an HTML-based app that not only works with Android, but also iPhone, Windows Phone 7, WebOS and more. The API is standardized, so you can use the same page on all the platforms.

There's support for the most common native features on most platforms. (Here's a chart of the features supported on each platform) In addition, if you find that there's a feature you cannot replicate using only their API, you can write a plugin in the native platform language (so, for Android that'd be Java), and then call that plugin from your HTML/Javascript-page.

Upvotes: 11

liori
liori

Reputation: 42277

There is Rhino, which is a Javascript engine written in Java. It works in Android, and it is used by Appcelerator's Titanium mentioned in another answer here.

User interface and Android-specific API can then be written and wrapped in Java, then called by the logic code written in Javascript and run by Rhino.

Upvotes: 2

Tarik
Tarik

Reputation: 81721

If you want to use javascript and access the native api then you should try Appcelerator.com. Those people are providing this.

Upvotes: 8

Related Questions