Android webservice practice? - android

I currently have a database and want my android apps to access a webservice and then access the database.
Currently i'm thinking of using either option. ksoap with asp.net that uses .asmx files created and also a page using asp.net that response.write json output. May i know which should be the better choice?

I would go the JSON route. Android has an API for parsing JSON built-in, and JSON format is more efficient in terms of size.
Aside from basic XML parsers, there's nothing built into android to handle SOAP, and from what I've seen, 3rd party offerings are limited.

Try this.The service is in php but should be simple to adapt ti asp.net.
http://www.embarcadero.com/rad-in-action/php-android

Related

what is the purpose of using JSON in android?

I need to know the purpose of using JSON in android ?
Please anyone tell me in a simple way...
Thanks
The same reason you'd use it on any platform. JSON is a way of storing and expressing information. It uses attribute-value pairs in a hierarchical structure. In Android specifically, you may need to download some information from a database, which could be stored in JSON and then read by your app. Alternatively, you could store data locally in JSON but there are probably better and more efficient ways to do that if you're not sending data across a network.
https://en.wikipedia.org/wiki/JSON
JSON is very light weight, structured, easy to parse and much human readable. JSON is best alternative to XML when your android app needs to interchange data with your server
For example, you can get data Json if you work with database. Or if you work with some API's then you can get data in format Json.
For example an app could fetch data from a server. When using JSON to get the data, the traffic is quite small and the app can easily work with it.
For example you have a server with a database with recipes, and your app displays recipes, the app could ask the server for recipes, and it gets a JSON in return. for example:
{
name: 'Cookies'
ingredients: { 'Butter', 'Eggs', ... /* I don't know, I'm not a chef :D */
...
}
The app can then just read the properties and display them in a neat list ;)
JSON (JavaScript Object Notation) is a lightweight format that is used for data interchanging. It is also a subset of JavaScript's Object Notation (the way objects are built in JavaScript
Pls go through this link: http://www.copterlabs.com/blog/json-what-it-is-how-it-works-how-to-use-it/
JSON stands for JavaScript Object Notation
JSON is lightweight text-data interchange format
JSON is language independent *
JSON is "self-describing" and easy to understand
* JSON uses JavaScript syntax for describing data objects, but JSON is still language and platform independent. JSON parsers and JSON libraries exists for many different programming languages.
Using JSON in Android is not different than using it on any other platform. The main advantage of the format (in comparison to XML for example) is the small size of the data. This is very important for mobile devices due to the scarce resource those application use - i.e. your mobile app should be able to run with little memory usage, slow internet connection and so on.
Besides Android's framework has built-in tools for parsing / creating JSON objects. Thus it is both easy and efficient to use JSON rather than XML. If you have any project specific reason to prefer another data presentation format - don't worry. It is perfectly fine NOT to use JSON as long as some other format is more suitable for your project.
In short JSON is usually the right choice due to its small footprint and easy of use.

creating a database for a website and mobile app

I want to create a database so both my website and mobile app could draw info from there.
I know how to execute queries with a website, but I have little to none experience with mobile applications.
I heard I can't just use any form of database(mysql, mongodb) because they are not compatible or something.
so how do I create my database so it will be compatible with android iOS and PC.
A few guidelines to get me started would be great :)
Sounds like you need to build an API to handle interaction between your mobile applications and your database, in much the same way your website communicates with your database. The primary difference will be that you will be returning JSON/XML to your apps, rather than displaying HTML to a user.
I thoroughly recommend JSON over XML as it is not as verbose and data usage will drop dramatically. However, if you're data structures are quite detailed / complex, go with XML.
To get started with building an API I'll recommend Slim PHP. You'll probably want some form of ORM also, for which I highly recommend idiorm/paris
The documentation for both of these frameworks is great, so have a dig around.
You can create a database with MySQL and draw info from your site with mysql queries. As for your mobile app, you can use some php pages and JSON Parser to draw data from the database. See example
As you say android doesn't support external databases such as MySQL. The easiest thing to do would be to create a MySQL Database that your website and android app can access.
The website would access the MySQL database as normal but the android app instead posts data such as variables to a PHP script, the PHP script can then get the retrieved data and perform the mysql queryies and json_encode the output and print the encoded data. The android app would then receive the outputted json format and the android app can then decode the json and process the data accordingly.
http://www.helloandroid.com/tutorials/connecting-mysql-database has some tutorials on how this can be done
You need to use Service - Oriented Architecture.
You may use REST API methodology for creating interfaces.
See this example
www.hassanpur.com/blog/2010/09/android-development-implementing-a-simple-client-server-model/

Why use JSON (objects) and not standard ArrayLists?

I commonly see data stored in JSON objects/arrays in open sourced Android code.
Why/When should I use JSON over normal Java ArrayLists?
JSON is a standard for transferring data between servers. It's a format that can be understood by any language, whether it be Java, C#, PHP, Python, Ruby, or JavaScript. Since it's a widely recognized format, it's much easier to work with JSON.
Many Android apps do communicate with a server, so it was probably easier for those developers to transfer the data to and from their server, which may or may not have been using Java.
If your client android application need data from a web service, then JSON data type can be used instead of XML because it's less character cost and it's easier to read

Need advice on .NET webservice method from Android application

I am accessing .NET webservice methods from my Android application using Java SOAP jar.
I am getting response for a specific webservice method as an array .
Do we have an API within the Java SOAP library to convert the response from array to XML(String) ?
Also , since using the external SOAP jar is around 90 KB in size , would like to know of an alternative approach by which we can access webservice , maybe a RESTful Web Services implementation or anything of a similar type, which wont require to add an external jar to the Android application & hence reduce the application size.
It would be nice if someone can come up with the changes to be done on the server end for implementing the RESTful WebServices in .NET & the client code for the same which I think will be only a HTTP connection .
Kindly provide your valuable *comments/code snippet*s on the same.
Try using "KSoap2" it is leightweight and it is open source so you add just the libraries to your project and you can implement your method returning pure XML.
http://ksoap2.sourceforge.net/

How to parse responses from a Django server in android?

In the Android application I am building, I want to be able to communicate with a local server developed in Django. (Basically a login page and a home page populated with posts and images from users) So do I need to use XML Parsers for the parsing the response from a Django server or is it possible for the server to respond with strings which can be directly used? Also what about images?
Is the JSON or XML Parser easier and robust to use in Android? The responses would be basically like tweets with a username, image and message. I was thinking of using the SAXParser. Any better alternatives?
Regards,
Primal
Android has built in libraries for parsing both JSON and XML.
In my opinion, the easier (and better) one would probably JSON if you're just looking to output the serialized version of your models.
Some relevant links:
JSON:
https://developer.android.com/reference/org/json/JSONObject.html
XML:
https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html
https://developer.android.com/reference/javax/xml/parsers/package-summary.html
Edit: In response to the last part of your question, yes, you can just output strings. Depending on the complexity of your data, you'll end up making things harder for yourself. Parsing JSON on Android is super easy. Just do it.
SAXParser is very easy to use, it just calls a method when it enters a node with the name of the node and its arguments.
So yes, using SAX is a good idea.

Categories

Resources