I plan on displaying dates and times in an android application but I am stuck on how I would implement this.
My Idea:
At the beginning of every month, a new calendar is downloaded. This information is displayed within the app and no internet connection is necessary for the rest of the app usage.
The information is in the form of an html table. How can I import this table, and display it within the App (also allowing the user to view only certain information in the table (querying the table))
Do I have to import this table into an sqlite database? or is there a less complicated way of doing this. I would like to limit the number of times the user has to access the internet, therefore it would be necessary to store the html table within the app itself.
How about save the table as an xml file? With the xml information you can query, or handle the data as array or list
Can you create a way to access your data in a more "friendly-way"? For example you could create an endpoint online where the app will send a request, download the JSON and save that in a internal database (SQLite, check this if you don't know how).
Or, the ugly way would be to parse the table in the device using Jsoup (which you tagged). Then it's the same, you should save it in a database and read the data from there.
By the way, I would not store directly the html table, because then you will need to parse it every time you need something (p.s it will be slow)
Related
I am developing an Android application to collect the store (Grocery) information.
The application have modules to create store, set it's attributes like address, lat lng, operating hours, manager details, building photos, etc.
Once the store is created user need to list down the assests of that store by clicking photos and providing it's details.
To store all this details, i have around 15 SQLite tables.
Now i want to implement feature of 'Synchronization', all this captured details need to send to server whenever connection is available otherwise detail should be stored locally and whenever connection is available it should move to server.
Also, please note that the number of tables may increase up to 40 as application grows.
I searched for the solutions/approaches for this on Google but in most of the article or example they have mentioned for small scale application having small data.
I have also implemented synchronization feature for small datatable (2 tables), where i checked for last updated timestamp on server and local and if it's different then we synchronize the data. I don't this i should use this approach for such large scale and large database.
I have one approach which doesn't depend on numbe of tables.
I am planning to have single table which store the following data
id
URL
request header
request body
Now let's say connection isn't available while sending request so it will be stored in table. Whenever connection is available it start reading the table and execute the request, on success it will remove the entry from table. With this approach we need only one table in SQLite.
The problem with this approach is when we want to retrieve data offline how we can do that? Do we need to have local database schema same as server?
Please guide.
Thanks
If you are syncing data with a server and you are removing local storage data ,which is incorrect as per my knowledge ,in this case your app does not work offline.So for that when you sync data to a server at that time maintain some flag which data is synced.And then next time just check flag status if it's synced then do not synced data otherwise do syncing.
I hope this solves your problem.
I am writing an app for a football fanclub and wanted to ask how I can display a football table in my app with the current standings, point goal difference and so on. I will create the table on my website but I don't know how to call it in my app, and respond to the changes I make online.
Now I had two ideas but I would like to know which one would be easier and how to implement them.
Should I do it with a webview that when online shows the table from the website and when offline shows a cached version?
Or should I somehow do it with a local database?
Or suggest something that would be even better/easier?
the best practice as i do, is to make a local database for this app,
then call a webservice to get information from the server that fills the web page as xml form, finally parse the xml and insert values into your database.
I am developing a places of interest app which will display the list of places of interest in a location.
When user chooses one, it will display more information and address etc.
How do I store all this data? Currently I am using a text file to store all the data and subsequently when user chooses a place, it will parse the text file and retrieve the necessary data for display.
Any advice on what is a better way to do this? I looked at SharedPrefs, but it is more like storing "key-value" pair and in this case I need to store a large amount of data.
I want the info to be available even when the device is offline, thus I can't download from an online server upon request.
Any other way to do this?
You may store it to XML file using XML serializer, here is very good tutorial for learning that,
http://www.ibm.com/developerworks/library/x-android/
and it can be easily parsed using Java XPath Api. Have a look at this at parsing XML files
http://www.ibm.com/developerworks/library/x-javaxpathapi/
Use SQLite
It can store large data.
It is available offline.
All your problems will be sorted out.
Hre we have a wonderful tutorial for sq-lite
http://www.vogella.com/articles/AndroidSQLite/article.html
How about a relational database?
http://developer.android.com/training/basics/data-storage/databases.html
Take a look at Serialization. If you do not need database access, you could define a class what holds every information you need. Then, you can do the following:
when you need to save the datas, you serialize your object, dumping its content to a file, for example on the SD card
when you want to load the datas, you just load the above mentioned file, and get back everything from the dumped file
I am using this method in my app to cache some datas that would need internet access, so the user can still view it, and with proper implementation, this can work very nicely.
Use database, create table and insert all the data in it. When you need the data just fire the query, and you are done.
SQLite is fine for Android.
Depending on the type of data you want to store, you could use a SQLite Database (provided with Android) if it has a normal database structure. You could Serialize your data and save it in a raw or encrypted file, making you data implement Serializable.
We've got an android app and an iPhone app (same functionality) that use sqlite for local data storage. The apps initially come with no data, then on the first run they receive data from a remote server and store it in a sqlite database. The sqlite database is created by the server and the apps download it as one file, which is then used buy the apps. The database file is not very large by today's standards, but not a tiny one either - about 5-6 MB.
Now, once in a while, the apps need to refresh the data from the server. There a few approaches I can think of:
Download a new full database from the server and replace the existing one. This one sounds like the simplest way to deal with the problem were it not for a repeated 5-6 MB downloads. The apps do prompt the user whether they want to download the updates, so this may not be too much of a problem.
Download a delta database from the server, containing only the new/modified records and in some form information about what records to delete. This would lead to a much smaller download size, but the work on the client side is more complicated. I would need to read one database and, based on what is read, update another one. To the best of my knowledge, there's not way with sqlite to do something like insert into db1.table1 (select * from db2.table1) where db1 and db2 are two sqlite databases containing table1 of the same structure. (The full sqlite database contains about 10 tables with the largest one probably containing about 500 records or so.)
Download delta of the data in some other format (json, xml, etc.) and use this info to update the database in the app. Same as before: not to much problem on the server side, smaller download size than the full database, but quite a painful process to do the updates.
Which of the three approaches you recommend? Or maybe there's yet another way that I missed?
Many thanks in advance.
After much considerations and tries-and-errors, I went for a combination of options (2) and (3).
If no data is present at all, then the app downloads a full database file from the server.
If data is present and an update is required, the app downloads some database from the server. And checks the content of a particular value in a particular table. That value will state whether the new database is to replace the original or whether it contains deletions/updates/inserts
This turns out to be the fastest way (performance-wise) and leaves all the heavy lifting (determining whether to put everything into one database or just an update) to the server. Further, with this approach, if I need to modify the algorithm to, say, always download the full database, it would only be a change on the server without the need to re-compile and re-distribute the app.
Is there a way you can have a JSON field for each of the tables? For instance, if you got a table named users, have a column named "json" that stores the JSON for each of the users. In essence, it would contain the information the rest of the fields have.
So when you download the delta in JSON, all you got to do is insert the JSON's into the tables.
Of course with this method, you will need to do additional work in parsing the JSON and creating the model/object from it, but it's just an extra 3-4 small steps.
I will recommend approach 3, because app will download the json file more fast and local db will be updated more easily avoid overhead of more internet usages.
Just create a empty db initially according to server db and then regularly updated the same by fetching json
I want users to be able to get additional content from my website which means I will insert the downloaded data into the device's SQLite. I am wondering if I am approaching this the right way..
My current approach is to create a REST web service which returns data in JSON format, parse the JSON and insert it row by row into the Sqlite db on the android device.
Is this the right approach? Will it be too slow if there are many table rows to be inserted at one time? Or is there a way to download another SQlite db and merge it with the local one?
I welcome any suggestion, thank you in advance for your answer.
I works, but you absolutely need to paginate : set a limit to the number of element sent by your rest service.
Another approach would be to download the complete sqlite database file at once, but that requires some tweaks. see http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/ (it is about embeding the database from the assets, but the preparation of the database is the same.)
A last point: large amount of insert, as well as downloading data from a server, must to be done in a separate thread or asynctask, from a service (not an activity that can be interrupted), or even better from a SynchronizationAdapter, which is called by the system itself.