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.
Related
I want to create a sqlite database file in a web service, so I dont have to read a json in the android device and wait for it to read the json, convert it to an object and then insert it to the database.
When the json is huge, with a lot of data, that process its to long for be waiting in an android device.
I would like to generate the database file of sqlite in the webservice, so that, instead of returning the json, it returns the sqlite database, and in android, I just need to save the database, so that, it is ready to use.
That would save a lot of time!
SQLite have libraries for almost any kind of server side language.
SQLite db is just a file so after is created you shall compress is in a zip and use volley library to dl the file over http.
Decompress the zip and connect to it.
I have no idea about which kind of data and which amount you need to transfer but if the data is organised properly the processing should be so long. Also you have to take in consideration that using JSON you can "ask" to receive only updates (delta) and this is something that is not possible if you download all the db each time.
Update: for this kind a data I would go to a different approach. Use docs from google publishing api to upload every specific period of time the db in an extension pack for your app. so most of the dl'ing process is even before the "install" on the device itself. When the app is first running will contact your server and get the latest updates since the db was created (I suppose that even that is a week you are talking about less than a hundred rows)...
I am trying to import some data from server to my android app. Server gets data from sql server and returns it throw a HttpRequest. I parse the data from HttpResponse and store it in sqlite database upon the JSONObject is parsed.
However the number of objects to be inserted is high and the operation may be canceled intentional(by pressing pause) or unintentional(internet problem). So I have below choices:
1- Ignore inserting into database after parsing JSONObject and wait for complete successful response from server: This solution is highly bad because if a problem occurs the user should start importing data again.
2- Make a feedback to server when I insert a row to database. So if I resume importing data just new records are imported from server: It is good but imposes extra network communication and also may affect performance.
3- Get one data packed file and try to parse it: So I am sure pausing the operation will not cause to data lost. But I prefer another solution rather than working with file.
What is the best way to handle this issue?
Thanks
I went through this choice two weeks ago.
I found the better way to manage these data is to build a web service in the server (for example, in PHP; i was using a wordpress blog), send to the web service an offset and limit request and then download the data in JSON format.
In this way, if you have 100 rows to query, you can tell the web service to give you the first 10 results, then you can parse and store them, and then, you can go back with another query asking the results from the row 11 to the row 20, and so on.
In this way, the app will manage many sequential requests (and the related low-weight JSON answers), instead of an extremely big JSON file.
You can also manage all these operation in background or with AsyncTask so, in the meantime, the user can work on the foreground activity.
I need some help, my app created a database on creation at the minute.
What I want is to get the information in a database on a server or PC and load it into my app.
It just needs to be from server to app, not back again.
I have no idea how I would do this, does anyone have any ideas?
first, I should say that your question is so wide. It contains alot of technologies.
So, I'll give you a breif walk through here. you should figure out the rest on your own. and then, you can come back and ask more specific questions.
That said, here is the path you should take:
On the server, implement a REST API that respond to the caller with the data in the server database.
example: http://your.server.com/api/somedata
calling this url with GET method should return the data you want in JSON format.
from your android application, call this url and save the response in a String.
parse the JSON String ( you can use gson ).
save the parsed data to your local database.
If you are the one developing the server api, then this book is a recommended reading:
RESTful Web Services
Update
Say you have a table in your server database called (TABLE) with the columns COL_1, COL_2, COL_3.
You could implement a php page called 'TABLE.php' that return the following:
{
"items": [
{"COL_1": "value_1", "COL_2": "value_2", "COL_3": "value_3"},
{"COL_1": "value_2", "COL_2": "value_3", "COL_3": "value_4"},
{"COL_1": "value_4", "COL_2": "value_5", "COL_3": "value_6"},
...
]
}
In your android application call http://your.server.com/api/TABLE.php page with GET method, parse the JSON returned (above) and save it to your local database.
You can do this for each database table on your server, until you have all your data saved locally in your android application.
This probably wont be the best design decision, but considering your knowledge about the topics, this could be a fair starting point.
Using HttpClient you can set things up to execute a POST to some servlet or similar app on the server. That app needs to then send data back to your Android app which is waiting for a response from the server. Then your app can parse the data and stuff it's own database.
I am missing some logic in my app. I am having json webservice which can be modiy by administrator.For the first launch of my app I am storing the data from the webservice and stores in sqlite and displays the data from sqlite using background threads.If it is second time launch then the app directly displays the sqlite data. Now the problem is if it is for the second time launch of the app how can I recognize the webservice got modified and where it is modified and how can I store the particular record?
For that I am comparing with the id's of the book in sqlite and webservice if new book enters I am able to get the new item and store it in the sqlite and display them from sqlite.But if there is any modifications in item details how can I recognize the particular tag?
Write a REST API on your web server that will send you a list of modified records. Query this API every time you start your app.
If there are modified records, This API should return you a list of the modified records which you can use to update your local sqlite database.
If not, then this API will return nothing and you can carry on happily :-)
You can create REST API's by writing server side code using a language like PHP, Ruby, Python etc
There are other options that avoid REST API's as well. See:
How to get from a MySql server to an Android app?
See here for a beginners tutorial on REST:
http://net.tutsplus.com/tutorials/other/a-beginners-introduction-to-http-and-rest/
First of all, the strategy that i have at the moment was achieved by searching here in stackoverflow, but by some reason, the "next step" was never mentioned here..
So i'm currently developing an android app that needs to fetch some data
from a remote database. I've searched in the web and at the moment i'm
able to get the data i want through a http request (rest webservice +
json response). My problem is, i can only fetch data of one database
query to my app in the same database session..
I wanted some strategy where i could send the http request, and them
perform 2 or 3 database querys and return them back to my app, without
the need to open 2 or 3 times a database connection, or sending one
http request for every query.
I know i can do some tricky manipulations with the json response, like
putting all the database query's response separated by some marks i
choose, but i was looking for some clean solution.
Can you help me achieve this pls?
Thanks
Unless you create some combined data structure which is the result of all the queries and then convert it to a JSON string, then your suggestion is the only other way to go, I feel. The combined data structure can then be recreated from the JSON received at the client end.