Vivek Padhye
Vivek Padhye

Reputation: 711

Android App Development Basics Questions

Trying to learn android app development. I need a general idea. I read that apps can be built with HTML5. But I know that HTML5 will allow only native apps, by which I mean, no server, no database nothing. Thats what I guess.
Like in web development we have PHP as server side language which handles all the server side operations, what is the server side language in android? Lets take example of instagram (I am not going to build something like that but just want to get the idea). It stores photos, users can like, share their personal info, store, delete etc. Can such app be made with HTML5? Or Java, Python is necessary for such heavy and complex application? If anyone could provide a proper info on android app development both native and web, I would be thankful.

Upvotes: 0

Views: 282

Answers (1)

EpicPandaForce
EpicPandaForce

Reputation: 81578

HTML5 can be used to replace the UI of the application - rather than using layouts and android components (LinearLayout, RelativeLayout - ListView, RecyclerView - TextView, Button, ImageView...) you'd use HTML/CSS/JS to display your UI in a web view. You can also specify click events in rendered HTML inside the webview, for which you could use @JavascriptInterface annotated methods in Java that would communicate to Android (reliable ONLY from 3.0 and above! It's bugged in 2.3!!!), so that you could execute logic on the Java level.

If you need to communicate with a server, then if you use HTTP (or maybe even HTTPS up to a certain point - client certificates are not supported), then you can even use jQuery $.ajax() requests.

Although there are a whole new level of problems that arise in the process. Error handling can become chaotic, CSS can be inconsistent among Android 4.3 and below versus Android 4.4 and above (unless you use the Crosswalk Project 1 2 which is 4.0+ only).

The biggest hassle of course is communicating from Java to Javascript, and from Javascript to Java. Please note that the @JavascriptInterface calls are done by the render thread of the WebView itself.

For that, I used this

(function(root) {
    root.bridge = (function() {
        var handlers = {};
        return {
            init: function () {
            },
            getHandlers : function() {
                return handlers;
            },
            callHandler : function(name, param) {
                if(param !== null && param !== undefined) {
                    Android[name](param);
                } else {
                    Android[name]();
                }
            },
            registerHandler : function(name, method) {
                if(handlers === undefined) {
                    handlers = {};
                }
                if(handlers[name] === undefined) {
                    handlers[name] = method;
                }
            }
        };
    }());
})(this);

As I explained here: https://stackoverflow.com/a/27426896/2413303

The server side is completely independent from the Android client. It can be stackless Python to PHP, Ruby on Rails or Java EE / Spring Framework, the Android client doesn't care - as long as you use REST API rather than web services. SOAP is hell on Android.

Upvotes: 2

Related Questions