I am using Backbone.js to build a 'hybrid' web app, which will be served as a native app using Phonegap. One thing I need is offline support for a large amount of data, and so we are considering using native code to synchronise the offline data with the server, and just transfer the bits of data we need to the web app when necessary. (An alternative approach we considered was using the Phonegap storage plugin but this is backed by WebSQL which seems to have a 5MB quota, which is too small for what we need).
As the app is based on Backbone.js, which expects a RESTful API as its backend, we are toying with the idea of embedding a RoutingHTTPServer into the native layer - essentially this allows us to embed a local web server in the app, so that the web layer can request data using standard RESTful calls to the local server. The beauty here is that the Backbone app doesn't know any different - the workflow is entirely the same as requesting data from a remote server.
I was wondering if there is an equivalent of RoutingHTTPServer for Android? I have seen projects like iJetty, but ideally I would like something which gives the REST-API bit out of the box too (like RoutingHTTPServer does). Would something like Spark work on Android?
Try MiniWeb Java Embedded Webserver. It is built for Android, super easy to setup JSON REST requests and open source.
Related
I need to create a HTML page with will interact with Sqlite database. This page and database will reside on an android device. This HTML page will be accessed by devices(PCs) connected to this android device locally. Since I have .NET background with no experience in Sqlite Or android etc, I am clueless as to what technology/language I will have to use. C# won't work I suppose.
Any suggestions? How do I go about it?
You can use the following tools/libraries to achieve what you want:
NanoHTTPD Server: A lightweight HTTP server for Android. You can read more about it on the Github project page. You can either use the bare server and add features like routing, etc. on top of it or use the Nanolets class provided by NanoHTTPD. There isn't much documentation around Nanolets but they are more-or-less like servlets for Android. To know more about them checkout this test file.
Room Persistence library: Room is a lightweight orm for SQLite developed by Google and is a part of the Android Architecture Components library. It abstracts away lots of boilerplate code you would have to otherwise write when using SQLite on Android.
Although, if you are just getting started on Android or are otherwise learning Android I would still recommend bare SQLite framework shipped with Android to know what is actually going on under the hood.
Using the above mentioned libraries, you can create a server on your device that can serve your requests. I would recommend that you develop a REST-like API for your service and interact with the API from JavaScript in the browser running on the PC.
You can use any JavaScript frameworks like Angular, React, Vue or even jQuery to build a single page front-end application to your service, bundle the JavaScript in a single package (using something like webpack) and ship the resulting bundle alongwith your Android app (preferably inside the /resources or /assets directory). You can the serve the bundle from Android device whenever another device connects to it, and then use the API to handle business logic.
I have no idea how does applications like Amazon, Flipkart etc work. They have both android application and website. How does data between both web and Android synchronise?
Do we write separate codes for building android app and website? If yes then in what language we build the website so that it's compatible with the android application.
And how to build the database for the same.
If answer is no to the above question, then how exactly do we proceed to build such Android and web application.
I am new to this and want to learn how to build it.
In general, web sites are built with web technologies such as JavaScript, HTML, and CSS, but there a many different frameworks and libraries in other languages (such as Angular, which is written in TypeScript) that can also handle the creation of web apps. In comparison, mobile applications for Android and iOS are written it Java/Kotlin or C#/Swift, respectively. There isn't really a clean, native way to create a single app for web and mobile platforms. But, the data that backs both of the platforms is the same.
How does this work? The data is hosted on what is called a backend, a server that has the information that you want to display to your users. Typically, the client app can get this information with an HTTP request to the backend, and the response will be the data formatted in a JSON string. Data is stored in the backend in a database. There are many databases in use today, but some more popular ones are MySQL, MongoDB, and SQLite, and each of them have their advantages and disadvantages. As you get further along in your development cycle, you will need to choose the tools that work for you.
Websites (and relative applications) like Amazon have very complicated systems behind what you see on the screen. Of course they have different code for either application and website. Usually, in small projects, you can create the mobile android app with languages like Java or Kotlin and websites with html, css and Javascript. But when it comes to get together data between an app and a website, you will need to write backend software, which is not so easy, for example in php and then create a database to store the data (with mySQL for example). Then you can access your data from either app and website and decide what to do with it. I suggest you to learn one of these technologies at a time. Trying to learn them all together will only create misunderstandings.
Hope I've been useful.
I'm starting a new side project in order to learn some new technologies and I have several doubts about the architecture I should use. My idea is developing an app both for web and for mobile (Android app mainly), so I think I need to implement the following:
REST API service (with django-rest-framework).
Web application (with django).
Android app.
After researching over stack overflow and Internet I have found 3 main "architectures" for the web part (server-rendering, client-rendering, and an hybrid model). In first place my idea was using the client-rendering model (with backbone or angular for the web client). However, I have seen that the hybrid model is a better choice.
So here are my doubts:
1) Could I use django for server-rendering the web application pages?
2) Does Django web app "use" the API or the API is implemented using the same "library" as the django web?
3) Could/should I use a client framework (angular, backbone) for the web client (being server-rendered) ?
Thanks in advance, and sorry about my short knowledge about django, etc.. This side project is just for that, to improve my knowledge about all this stuff.
I don't use Django but I am currently using Angular with Flask as my REST backend. I think the hybrid approach is useful if your app benefits from caching rendered content. An example would be something like a blogging site where you may store Markdown but render HTML and thus the content is largely unchanging. If this content is shared across many users it can be very beneficial to generate once on the server and serve it to many clients.
However if your reasoning is that because mobiles are relatively under-powered server-side rendering will improve the render time, this does not necessarily hold true. Serving the JSON data model will typically result in less network traffic (obviously dependent on browser caching) which is important for mobile client responsiveness.
For my own part I prefer to render on the client and keep the server-side rendering to some very minimal templates. I find this results in a much better REST API that I can then use to provide external developer access or plug in other client UIs. My client code lives on the client side in Angular, my REST interface is clean, and security is always uppermost in my mind because I have to assume that the client code is potentially hostile.
That said I can see a use for server-side rendering even with Angular. For content that is fairly static it would be great to generate this server side, cache it, and then ngInclude it.
I want to built a mobile application using Phonegap that will communicate with the restful web services and parse the json data.There are two ways two do it:
Calling restful web services using http connection in Java and connecting the Java code to JavaScript file by making our own plug-in in cordova.
2.Making ajax calls to communicate with rest services.
Which one is better considering the needs below:
1.It can call https web service,since for https in android we need to include certificates,create bks file for that which includes lot of mess.
2.It should be able to receive and parse the json data and render it to the html page.
3.We need to built this app for primarily android OS but if we can built it for ios,windows etc. It would be better.
Please tell me if i am using right tool,if sencha touch is easier to perform these tasks?
I would suggest that you use AJAX because it completely fits all your needs, and you gain to use the same code for future use if you'll ever decide to build for more platforms.
moreover, why make things complicated? you already writing your app using javascript, so don't mix it with native code when its unnecessary.
The fact that you choose PhoneGap, it is an indication that you are wanting to re-use your HTML/JS/CSS expertise as much as possible. Say if you choose jQuery Mobile (or any other framework) for your project, jquery provides ajax for your needs already and there is no reason to go down to the JAVA layer.
That said, the right approach should be using the ajax mechanism provided by your javascript framework. This is your option-2 and you won't need to build the raw ajax utilizes. Like if you go with jQuery/jQueryMobile + Backbone + backbone.marionette (we happen to use them in phoneGap app), there are a lot of add-ons out there to help. Like in this example, it is actually part of the phoneGap app under 'www' directory.
Also the communication to the webservice is your least concern if you have all the tools. Making suggestion on what tools to use is not allowed by Stackoverflow:-)
I'm building an application for android which collects user data.
Also I'm going to build a website which will use that data where users can have an account and synchronize data with phone and website (I guess it's quite common setup).
Site will be using MySQL database, but I want it to be database independent using some kind of API.
I think I'm going to use Python for website (Django).
Since I haven't started whole synchronization part yet I have a question on how to do it best.
Which protocol to use - JSON, SOAP, XML (any other)? Which is best supported in android?
What are the best practices in doing such a thing?
Leonti
Android lacks a built-in API for processing SOAP or XML-RPC requests, so I would go with a REST-style Web service. JSON is probably the easiest from an Android perspective to consume and create.