Load remote String content into arraylist in Android? - android

On the server side I have a php script that connects to my mysql database and echo's string based on myurl.com/connection.php?id=22 where the 22 in the example obviously is the id for the string I want.
In my Android application I want to fill an arraylist with like 100 strings, but I am unsure how to do so, and what the best approach for doing it is.
As I understand I need to use asynctask to free the main thread from the process, and I have also looked at httpget although I am not sure if that is the only way of loading remote server content?

so from the my sql database the string values are returned ? right ?
the best way to do it is make the output from the server in json format and in your andriod app read the stream from the page and using json read fuctions and add the contents to your arralist using list . add() ; function...

Related

search through web-service with json

In my android application im using web-service to get information about food the problem that if i write appl instead of apple,row,skin it dosent fill automatically and an error message will be shown,, what i did i stored 2000 name from web service in sqlite and search through them is it wrong to do this ? and how can i search with misspelling in web-service without the error message ?
The api url http://api.nal.usda.gov/ndb/search/?format=json&q=apple&sort=n&max=25&offset=0&api_key=DEMO_KEY
Salam Enas,
If the data do change frequently (like a movies list) then it's not ok to store it in the sqlite and it's better to be stored in the server database.
If the data does not change frequently, then it's ok to store them on the sqlite database although the app size will increase by 2 Mb which is a drawback.
You may also want to consider other APIs if you are not committed to use this one.
When storing data on the server, HTTP requests burden can be alleviated by caching data on the mobile.
good luck :)

Creating a database 'buffer'? Android

I am writing an application that allows notes to be written on a web interface, and then be viewed on a handset.
I have gotten it into place using:
JSON + PHP scripts to get table information
Creating a class for 'note'
Filling an ArrayList with JSON code
If JSON code == "" then read in JSON string from local SQL
if JSON code has text (i.e website has been reached), then delete all from local SQL and then update local SQL with new JSON string (this is inefficient I know but I'm a novice and it's sort of the chain of steps I figured out myself and I don't care about having 'backups' or whatever.
The problem I have though, is now I want to mark as complete, and at the moment when the button is pressed, a PHP script is run, and the MySQL web DB gets updated, and then the phone next reads in the JSON code again and updates its local DB.
The issue is if I have no connection, I don't know what to do, because the code will be set locally but when it next connects it will copy in the code over the local SQL and the task will be set as incomplete again.
Is there any way I can create a sort of 'buffer' i.e keep trying to run php script when connecting or something before the website next gets contacted and values get read in?
Sorry if I'm being a bit slow or missing something here I've been working for hours now I'm going a bit loopy haha.

External Database and Android application

I am creating an android application which records soccer scores.
I have an external mysql database created on my own host.
How do i retrieve the data from the database in order to display it in my application?
Thanks in advance!
You need to write a service hosted on your database using either php or some other language you are comfortable which exposes data as XML/JSON.
Android has HTTPURLConnection capability,using which you can query your service by passing the parameters. Your service queries database and consturcts data either as XML or JSON using libraries and returns to app.
Your app need to parse the response (if XML, using SAX/DOM or someother APIs, if JSON using Android in-buit json parser) and display. Here is an example on how to do.
If you also want to retrive the information to be used offline, you can create an empty database locally, and update it by passing SQL statements. This is not the most efficient way to do it, but it worked for me since I am not working with a huge db.
Otherwise, use HTTP connection connecting to your remote host and pass the result via JSON object.

Android https timeout

I am getting huge data from a database and I have to display the data in a table form. Please provide me a way to get the data from the web service and display it in a table.
You should get data from web and parse it then put all the data on map/list/arrays then create custom list according to your need then put this data structure in listview.
Your best bet is to actually use HTTP client or url connection with a buffer for reading to get the data (search on google for tutorials and examples). also be sure to set a larger timeout because you will be pulling a lot of data. then depending on the format of your data start parsing it, maybe store it in a database, Arraylist or something like that and then make a list with an adapter to show the data.
Url connection
hope this helps.

how to integrate servlet/jsp page in android application?

I want to store & retrieve the data from android web application to MySQL through jsp/servlet.
is it possible ? how : any other way to do this things.
thanks in advance.
Probably the easiest way is to use JSP/SERVLET as a middle layer, then send HTTP requests from your Android application to it.
To retrive data:
At JSP/SERVLET [Server] side code to:
connect to the database
run an SQL query, query may contain WHERE block depending on data from POST/GET
values
At Android [Client] side code:
use a HttpPost for sending the parameter value
convert response to string
parse the data and use it as you want.
Same way you can add new entries in database.
For reference look here or you can also use HTTPConnection.

Categories

Resources